Skip to content

Commit

Permalink
webcompat#710 Adds parameters to save all frames for an animated GIF
Browse files Browse the repository at this point in the history
  • Loading branch information
karlcow committed Mar 10, 2016
1 parent 577dcca commit 3240856
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions webcompat/api/uploads.py
Expand Up @@ -86,6 +86,11 @@ def save(self):
# Optimize further the image compression for these formats
if self.image_object.format in ['JPEG', 'JPG', 'JPE', 'PNG']:
save_parameters['optimize'] = True
# If animated GIF, aka duration > 0, add save_all parameter
if (self.image_object.format == 'GIF' and
self.image_object.info['duration'] > 0):
save_parameters['save_all'] = True
# unpacking save_parameters
self.image_object.save(file_dest, **save_parameters)


Expand Down

4 comments on commit 3240856

@karlcow
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self. For animated gif, in fact we want to leave it as-is, because the color palette is being destroyed after the first frame.
It's a known issue of Pillow python-pillow/Pillow#1525

@karlcow
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue is in fact with the save line. it means that if we want to avoid the effect on animated GIF. We have to fix it with one of the proposed hack on Pillow or to avoid Pillow for animated GIF. grmph.

(thinking mode)

@karlcow
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! useful is_animated discovered in
https://github.com/python-pillow/Pillow/blame/master/PIL/GifImagePlugin.py#L108

>>> from PIL import Image
>>> im = Image.open('/Users/karl/Desktop/animated.gif')
>>> im.info
{'duration': 90, 'version': 'GIF89a', 'extension': ('NETSCAPE2.0', 885), 'background': 0, 'loop': 65535}
>>> im.is_animated
True
>>> 

@karlcow
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a way to fix it in pillow
python-pillow/Pillow#1717 (comment)

Let's see how this is flying.

Please sign in to comment.