Concatenating images using python
To generate sprites for a game I'm working on I needed to concatenate images side by side. I wrote a little python script to do the job. It requires the PIL.
from PIL import Image import sys if not len(sys.argv) > 3: raise SystemExit("Usage: %s src1 [src2] .. dest" % sys.argv[0]) images = map(Image.open, sys.argv[1:-1]) w = sum(i.size[0] for i in images) mh = max(i.size[1] for i in images) result = Image.new("RGBA", (w, mh)) x = 0 for i in images: result.paste(i, (x, 0)) x += i.size[0] result.save(sys.argv[-1])
Jonas Wagner
Nice example, I recently had to do something similar, and your post provided a good source to start working.
Comment by geo — 8/12/09 8:05 AM | # - re
Good code, thanks for sharing.
Comment by Ngan hang — 10/19/09 9:15 AM | # - re
helpful post to start working,
thanks.
Comment by umar — 11/19/09 6:48 AM | # - re
thanks!
it was very helpful for me
Comment by skyfrog — 7/26/10 7:29 AM | # - re