png_strip.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import glob
  4. import argparse
  5. import Image
  6. if __name__ == "__main__":
  7. parser = argparse.ArgumentParser(
  8. description="Generates single png strip from multiple images. Just "
  9. "copy it to folder and run."
  10. )
  11. parser.add_argument("-p", "--pattern",
  12. help="searching files pattern ", default="*.png")
  13. parser.add_argument(
  14. "-d", "--dest", help="destination file", default="anim.png")
  15. args = parser.parse_args()
  16. images = []
  17. w = 0
  18. h = 0
  19. size = None
  20. for g in sorted(glob.glob(args.pattern)):
  21. im = Image.open(g)
  22. images.append(im)
  23. h = max(h, im.size[1])
  24. w += im.size[0]
  25. if not size:
  26. size = im.size
  27. print(("appending image: '{}' with size ({}, {}) ".format(
  28. g, im.size[0], im.size[1])))
  29. if size[0] != im.size[0]:
  30. print(("warning! width should be {}".format(size[0])))
  31. if w:
  32. anim = Image.new("RGBA", (w, h))
  33. w = 0
  34. for im in images:
  35. anim.paste(im, (w, 0))
  36. w += im.size[0]
  37. print(("writing result...\nfile=\"{}\" cols=\"{}\"".format(
  38. args.dest, len(images))))
  39. anim.save(args.dest)