Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Image.show() defaults to PNG ignoring animated GIFs

Open seidnerj opened this issue 3 years ago • 1 comments

When using show() for an animated GIF with version 9.2.0, Pillow converts to image to PNG by default thus eliminating the animation.

I suggest the following change in "ImageShow.py" to preserve the animation:

def save_image(self, image):
    """Save to temporary file and return filename."""

    if image.format == 'GIF' and image.is_animated:
        suffix = "." + image.format
        f, filename = tempfile.mkstemp(suffix)
        os.close(f)

        image.save(filename, save_all=True)

        return filename
    else:
        image_format = self.get_format(image)
        return image._dump(format=image_format, **self.options)

seidnerj avatar Sep 22 '22 21:09 seidnerj

PNG also supports multiple frames. If we were going to add this feature, I would recommend still using the PNG format, as GIF frames are limited to 256 colors.

radarhere avatar Sep 23 '22 01:09 radarhere

I've created PR #6611 to do so, and PR #6610 to fix a problem when saving GIFs as animated PNGs.

radarhere avatar Sep 23 '22 10:09 radarhere

Hehe, I was just faced with what you fixed in #6610 when I tried rewriting this to work as an animated PNG and was working to fix that :)

Nice! thanks a lot.

seidnerj avatar Sep 23 '22 10:09 seidnerj