Skip to content
Advertisement

Merging of Three Images in Single Row And Fourth Image in Next Row Using PIL In Python

I am trying to merge multiple images and as per requirement its working as explained below.

I am expecting 3 images should come in one single row and 4th image should come in next row but as per provided output for below image i am getting improper sequence of images i.e. Cat, Dog and Apple should come in one single row as per my code given below. Currently mouse image is also is coming with Cat, Dog and Apple as well as Apple image is not visible.

enter image description here

JavaScript

Expected Output :- I want to display Cat,Dog ,Apple in single row and mouse in next row.

Please help me with solution.

Thanks In Advance !!

Advertisement

Answer

You just need to use proper total_width and total_height in your output image. Since you need two rows, the total_height should be 2*min_height. The total_width should be just the sum of width of the first three images. Also, the x-coordinate for the new line should be 0 (or 5 since you are using a margin of width 5)

JavaScript

The final output appears as shown below: enter image description here The trailing black areas in each row are because of reserving extra width to handle the image with maximum width. In this example, the number 10 has a larger width than the others, so we used the width of 10 to define our total width.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement