Python Image Library: How to combine 4 images into a 2 x 2 grid?

The only problem there is that “paste” does not return an image object – it rather modifies the “blank” image inplace.

So, when the second paste is called (the one that uses the fuild128 image), it tries to be applied on “None” – which is the return value of the first image.

If that is the only problem you are having, just make one paste call per line, like this:

blank_image.paste(image64, (0,0))
blank_image.paste(fluid128, (400,0))
blank_image.paste(fluid512, (0,300))
blank_image.paste(fluid1024, (400,300))
blank_image.save(out)

Although it looks likely you’d need to scale each image so that their format match as well.
And your code for the “image_num” variable is unecessary. Python is really good with strings – just do something like this:

image64 = Image.open(fluid64 + "%02d.jpg" % pic)

Leave a Comment