Resizing and combining multiple png images

I wanted to combine multiple images to one figure and add letter annotations for the figure legend. I wanted to do this in Python, of course, and below is what I came up with. Some of it is hardcoded since it obviously depends on the size and preferred combination of your images. I will combine 6 png images in one png figure, the result is below. The plots were made using NanoPlot and NanoComp.


I found inspiration in the following blog post and StackOverflow questions:

Images are opened and resized to match width with the smallest image. I make two vertical stacks after converting the images to a numpy array. After changing the height of these two images (‘left.png’ and ‘right.png’) I combine these two finally in one image, after which I add the letter annotations for the figure legend.

This is the code I used:



2 thoughts on “Resizing and combining multiple png images

  1. Hey, quick edit suggestion:
    lines 17 and 18 should be:
    proportional_height = int(img.size[1] * wpercent)
    return img.resize((width, proportional_height), Image.ANTIALIAS)


    1. Hi Nathan,

      Thanks for the feedback. I haven’t used this in a long long time, but what you write sounds reasonable. I’ll trust you on this one and have corrected the lines.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s