我想使用python和PIL或PythonMagick更改GIF动画图像的大小。我找不到解决方案。 PIL和缩略图方法适用于jpg和png但不适用于gif。 ImageMagick有命令mogrify / convert -resize'1280x1024>'但我找不到文档,我不知道怎么用pythonmagick。
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. ImageMagick has command mogrify/convert -resize '1280x1024>' but i can't find documentation and i don't know how to do it with pythonmagick.
任何人都知道解决方案?
Anyone knows solution?
在最坏的情况下,我使用os / subprocess并转换; -S
In the worst case i use os/subprocess and convert ;-S
谢谢。
推荐答案您可以使用PIL和 images2gif ,一个基于PIL的简短模块链接到这个博客页面,并提供此处。用于处理此 rose.gif 的代码如下。我将 images2gif.readGif '读为numpy数组'属性设置为 false 以获取PIL图像列表所以我可以使用PIL 缩略图函数。
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:已处理:
Orignial: Processed:
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).
更多推荐
调整GIF动画,pil / imagemagick,python
发布评论