How to insert an image into a larger image using a pillow?

I have a pretty simple code file:

from PIL import Image til = Image.new("RGB",(50,50)) im = Image.open("tile.png") #25x25 til.paste(im) til.paste(im,(23,0)) til.paste(im,(0,23)) til.paste(im,(23,23)) til.save("testtiles.png") 

However, when I try to start it, I get the following error:

 Traceback (most recent call last): til.paste(im) File "C:\Python27\lib\site-packages\PIL\Image.py", line 1340, in paste self.im.paste(im, box) ValueError: images do not match 

What causes this error? These are both RGB images, documents do not say anything about this error.

+8
python python-imaging-library pillow
source share
1 answer

The problem is the first insertion - according to the PIL documentation ( http://effbot.org/imagingbook/image.htm ), if the argument "box" is not passed, the size of the images should match.

EDIT: I actually misunderstood the documentation, you are right, it is not. But from what I tried here, it seems that the second argument is not being passed, the sizes should match. If you want to save the second image size and place it in the upper left corner of the first image, just do:

 ... til.paste(im,(0,0)) ... 
+13
source share

All Articles