Python Forum
PIL: "ValueError: Images do not match"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PIL: "ValueError: Images do not match"
#1
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:
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: time data 'None' does not match format '%Y-%m-%dT%H:%M:%S.%f' rajesh3383 4 14,630 Sep-03-2020, 08:22 PM
Last Post: buran
  getting error ValueError: time data '' does not match format '%H:%M' srisrinu 2 5,613 Apr-09-2020, 11:12 AM
Last Post: srisrinu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020