Resize GIFs, pil / imagemagick, python

I want to resize GIF animation images using python and PIL or PythonMagick. I can not find a solution. The PIL and thumbnail method works for jpg and png, but not for gif. ImageMagick has the command mogrify / convert -resize '1280x1024>', but I can not find the documentation, and I do not know how to do it with pythonmagick.

Does anyone know a solution?

In the worst case, I use os / subprocess and convert; -S

Thanks.

+7
source share
2 answers

You can use PIL and images2gif , the short PIL-based module associated with this page and available here . The code used to process this rose.gif is below. I set the images2gif.readGif property 'read as numpy array' to false to get a list of PIL images to use the PIL thumbnail function.

Orignial: rose Processed by: small rose

 import Image import images2gif frames = images2gif.readGif("rose.gif",False) for frame in frames: frame.thumbnail((100,100), Image.ANTIALIAS) images2gif.writeGif('rose99.gif', frames) 

I'm not sure how to maintain transparency; my attempts to do this have failed (for now).

+12
source

Some amazing person made an updated version of images2gif.py that takes into account transparency:

https://bitbucket.org/bench/images2gif.py/overview

There are some more artifacts, but it's better than the original!

+3
source

All Articles