I opened a PNG image that behaves sort of like a GIF , then I tried to save.
No error, image saved normally.
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
from PIL import Image
im = Image.open('problem.png')
im.save('out.png')

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 :)
Most helpful comment
I'll look into this when I get a chance, but probably won't be until this weekend at the earliest