I have almost 200 images (.png
files) that I want to assemble together into one PNG file. All the image files have the same dimensions (705 x 1000).
I want to make 20 rows of 10 images each row, with 10 pixels horizontally between each image and 10 pixels between each row.
How can I do this programmatically? Can this be done with Python? Can I avoid having to do this manually using a word-processing or other other office style program?
CodePudding user response:
I did some Googling and found my answer.
The Pillow Python package is exactly what I was looking for.
It can merge images as such:
from PIL import Image
def merge(im1, im2):
w = im1.size[0] im2.size[0]
h = max(im1.size[1], im2.size[1])
im = Image.new("RGBA", (w, h))
im.paste(im1)
im.paste(im2, (im1.size[0], 0))
return im
(taken from Official Pillow docs)
This is enough to get me started!
CodePudding user response:
With ImageMagick in Terminal, using:
magick montage *.png -tile 10x20 -geometry 10 10 result.png
If Python is a hard requirement, which doesn't seem to be the case from your question, you can use wand which is a Python binding to ImageMagick.