Pillow: Error on saving APNG

Created on 24 Jun 2020  路  4Comments  路  Source: python-pillow/Pillow

What did you do?

I opened a PNG image that behaves sort of like a GIF , then I tried to save.

What did you expect to happen?

No error, image saved normally.

What actually happened?

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python38\lib\site-packages\PIL\Image.py", line 2100, in save self._ensure_mutable() File "C:\Python38\lib\site-packages\PIL\Image.py", line 617, in _ensure_mutable self._copy() File "C:\Python38\lib\site-packages\PIL\Image.py", line 610, in _copy self.load() File "C:\Python38\lib\site-packages\PIL\ImageFile.py", line 262, in load self.load_end() File "C:\Python38\lib\site-packages\PIL\PngImagePlugin.py", line 921, in load_end self._prev_im.paste(dispose, self.dispose_extent) ValueError: images do not match

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.8.3
  • Pillow: 7.1.2
from PIL import Image
im = Image.open('problem.png')
im.save('out.png')

problem

Bug

Most helpful comment

I'll look into this when I get a chance, but probably won't be until this weekend at the earliest

All 4 comments

A quick check: it's coming from PngImageFile.load_end because dispose.mode is RGBA and self._prev_im.mode is P here:

            if dispose:
                self._prev_im.paste(dispose, self.dispose_extent)

And they must match in ImagingPaste in Paste.c (the x and y sizes all match, mode is pixelsize):

    if (xsize != imIn->xsize || ysize != imIn->ysize ||
        pixelsize != imIn->pixelsize) {
        (void) ImagingError_Mismatch();
        return -1;
    }

ping @pmrowla

I'll look into this when I get a chance, but probably won't be until this weekend at the earliest

I've created PR #4742 to resolve this. Feel free to comment @pmrowla if you have any thoughts.

Thank you @radarhere :)

Was this page helpful?
0 / 5 - 0 ratings