用ImageMagick中的convert以及其它的gifsicle对GIF动态图片进行尺寸修改

为了方便在线交流,高清大图的GIF往往需要改小,如果逐帧修改则太麻烦.

ImageMagick中的convert可以完成这个工作,

点击打开链接



11
down vote accepted

first run:

convert do.gif -coalesce temporary.gif

then

convert -size <original size> temporary.gif -resize 24x24 smaller.gif

但是效率低而且输入的命令比较复杂,参考同一链接下的方法

-coalesce "creates a complete view of the animation at each point, a bit like a true film strip, rather than an animation sequence. Such a sequence, known as a Coalesced Animation is much easier to study, edit, modify and re-optimize."  –    sam   Aug 12 '13 at 19:26

 
5 
gifsicle --resize 24x24 > do-24.gif can to this too  –    sam   Aug 14 '13 at 2:20
 
Note that the coalesced view is much larger than the optimized one (3.2 times in my test), and the resizing produces a coalesced image, which can also be larger than the original in file size (2.3 times in my test) even if the resolution is smaller. When I try resizing directly it looks fine and has a small file size, though maybe it just works for this image.  –    endolith   Dec 27 '14 at 21:49

居然是从ANSYS里面找到了 gifsicle 这个文件, 然后果然效果又快又好!


例子: 原始的GIF文件因为大于2MB而不能上传,改小之后OK


不过gifscicle虽然提高了速度,但是在稳健性方面比convert果然差一些;

实际使用发现,在个别gif转化中gifscicle会使导出图片有发花的效果,而convert无这种不良现象.

比如:

convert得到的结果:

gifsicle得到的结果:

(后来升级到最新的gifsicle没有这个问题了,而且gif优化得很好)


用Python应该也可以实现, 


有时候不喜欢原始GIF图片中的太多无内容的margin, 则还可以用convert实现crop之:

点击打开链接


convert input.gif -coalesce -repage 0x0 -crop WxH+X+Y +repage output.gif
  • Animated gifs are often optimised to save space, but imagemagick doesn't seem to consider this when applying the crop command and treats each frame individually.-coalesce rebuilds the full frames.
  • Other commands will take into consideration the offset information supplied in the original gif, so you need to force that to be reset with-repage 0x0.
  • The crop itself is straightforward, with width, height, x offset and y offset supplied respectively. For example, a crop 40 wide and 30 high at an x offset of 50 = 40x30+50+0.
  • Crop does not remove the canvas that it snipped from the image. Applying +repage after the crop will do this.

类似地gifsicle也能完成同样工作,但是,同样需要谨慎使用:

a program called Gifsicle and it works great for manipulating animated gifs.

gifsicle --crop 0,0-100,100 input.gif >output.gif

It can also do all sorts of other operations. Check it out!



关于ImageMagick的系列命令和用法,CSDN博客上还有其它的介绍:

点击打开链接


关于 gifsicle 不得不提的两个链接:


1. Github: https://github.com/kohler/gifsicle

2. Homepage: http://www.lcdf.org/gifsicle/


设置延迟,和添加


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值