I'm trying to write a script which selects part of a given image and tiles it in one of a variety of ways. For this, I'm using pillow (archlinux's packages of python 3.6.4 and python-pillow 4.3.0, which provides PIL). For the part of the script in question, I'm trying to paste one image, with a mask, into another image. Throughout my script, I have done this multiple times with no issues. However, this particular time I get a ValueError. After searching on the Internet, I've checked the source and destination image modes (both RGB) and sizes (source 92x78, destination 92x92). I cannot figure out the difference between this and the successful times.
The (cut down) code:
The (cut down) code:
from PIL import Image, ImageDraw # Provided rather than calculated, for simplicity fapo = 92.38795325112868 width = 76 apo = 92 x = 57 y = 537 hv_mask = Image.new('1', (apo, apo)) draw = ImageDraw.Draw(hv_mask) draw.polygon([(0, round(fapo/2)), (apo, round((apo-width)/2)), (apo, apo-round((apo-width)/2))],fill=255) del draw pic = Image.open('testimage.png') # pic.size = (988, 800) pic_crop = pic.crop((x, y, x+apo, y+apo)) temp = pic_crop.rotate(45, expand=1) temp2 = temp.crop((0, round((temp.size[1]-width)/2), apo, width+round((temp.size[1]-width)/2))) temp3 = Image.new('RGB', (apo, apo)) temp3.paste(temp2, mask=hv_mask, box=(0,0))
Error:Traceback (most recent call last):
File "Untitled2.py", line 23, in <module>
temp3.paste(temp2, mask=hv_mask, box=(0,0))
File "/usr/lib/python3.6/site-packages/PIL/Image.py", line 1402, in paste
self.im.paste(im, box, mask.im)
ValueError: images do not match