Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

ValueError: images do not match

Open alanhamlett opened this issue 1 year ago • 8 comments

Without changing code, only upgrading from 10.1.0 to 10.2.0, started getting this error when generating animated GIFs:

  File "wakatime/insights/utils.py", line 481, in get_animated_insight
    images[0].save(out, format="gif", append_images=images[1:-1], save_all=True, duration=80, loop=0)
  File "venv/lib/python3.10/site-packages/PIL/Image.py", line 2439, in save
    save_handler(self, fp, filename)
  File "venv/lib/python3.10/site-packages/PIL/GifImagePlugin.py", line 704, in _save_all
    _save(im, fp, filename, save_all=True)
  File "venv/lib/python3.10/site-packages/PIL/GifImagePlugin.py", line 715, in _save
    if not save_all or not _write_multiple_frames(im, fp, palette):
  File "venv/lib/python3.10/site-packages/PIL/GifImagePlugin.py", line 671, in _write_multiple_frames
    diff_frame.paste(fill, mask=ImageOps.invert(mask))
  File "venv/lib/python3.10/site-packages/PIL/Image.py", line 1738, in paste
    self.im.paste(im, box, mask.im)
ValueError: images do not match
  • OS: Linux
  • Python: Python 3.10.12
  • Pillow: pillow==10.2.0

alanhamlett avatar Feb 03 '24 22:02 alanhamlett

Thank you for reporting an issue.

Please include a self-contained, copy-pastable example that generates the issue if possible. Be concise with code posted. Guidelines on how to provide a good bug report:

  • https://stackoverflow.com/help/mcve

Bug reports which follow these guidelines are easier to diagnose, and are often handled much more quickly.

Please include code that reproduces the issue and whenever possible, an image that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies.

hugovk avatar Feb 03 '24 22:02 hugovk

Looks like this commit is the culprit: 55c5587437669389bd7b0044753b47ca43afe59e

alanhamlett avatar Feb 03 '24 23:02 alanhamlett

Yes, that would be the cause - but rather than just undoing that change, it would be better to adjust it, to both reduce filesize and to fix your problem. The quickest way of understanding how to do that would be for you to post a self-contained example of your problem.

radarhere avatar Feb 04 '24 03:02 radarhere

Here's a repo to reproduce the bug: https://github.com/alanhamlett/pillow-issue-7777

alanhamlett avatar Feb 04 '24 08:02 alanhamlett

Thanks.

0.png, 4.png and 5.png are 120px wide. 1.png, 2.png and 3.png are 108px wide.

The images you are using to create your GIF are not all the same size. So, as error says, the images do not match.

If you change them to all be the same size, the error goes away.

radarhere avatar Feb 04 '24 10:02 radarhere

Got it, so it should have raised that exception in previous versions too. Thanks!

alanhamlett avatar Feb 04 '24 10:02 alanhamlett

Actually, looks like animated GIF format supports images of different sizes. Should Pillow also?

alanhamlett avatar Feb 04 '24 10:02 alanhamlett

I've created PR #7779 to resolve this.

radarhere avatar Feb 05 '24 08:02 radarhere