Resize GIF animation, pil/imagemagick, python

前端 未结 2 1821
予麋鹿
予麋鹿 2021-02-01 10:29

I want to change size of GIF animation image using python and PIL or PythonMagick. I can\'t find solution. PIL and thumbnail method works for jpg and png but not for gif. ImageM

相关标签:
2条回答
  • 2021-02-01 10:48

    Some amazing person made an updated version of images2gif.py that accounts for transparency:

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

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

    0 讨论(0)
  • 2021-02-01 11:05

    You can use PIL and images2gif, a short PIL based module linked to on this blog page, and available here. Code used to process this rose.gif is below. I set the images2gif.readGif 'read as numpy array' property to false in order to get a list of PIL images so as I could use the PIL thumbnail function.

    Orignial: rose Processed: 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 preserve transparency, my attempts to do so have failed (so far).

    0 讨论(0)
提交回复
热议问题