I've got a fairly 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 attempt to run 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 is causing this error? They are both RGB images, the docs don't say anything about this error.
The problem is in the first pasting - according to the PIL documentation (http://effbot.org/imagingbook/image.htm), if no "box" argument is passed, images' sizes must match.
EDIT: I actually misunderstood the documentation, you are right, it's not there. But from what I tried here, it seems like passing no second argument, sizes must match. If you want to keep the second image's size and place it in the upper-left corner of the first image, just do:
...
til.paste(im,(0,0))
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With