如何使用 ImageMagick 裁剪动画 gif? [英] How do I crop an animated gif using ImageMagick?

查看:37
本文介绍了如何使用 ImageMagick 裁剪动画 gif?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有大量关于裁剪图像的信息,但尝试裁剪(或修剪)动画会产生奇怪的结果.有时它们会闪烁,或者带有额外的帧,或者某些帧正确裁剪而其他帧偏移.我如何防止这一切发生?

There's plenty of information about cropping images, but attempting to crop (or trim) animations produces strange results. Sometimes they flicker, or come with extra frames, or some frames crop correctly and others become offset. How do I prevent all this from happening?

推荐答案

convert input.gif -coalesce -repage 0x0 -crop WxH+X+Y +repage output.gif

  • 动画 gif 通常经过优化以节省空间,但 imagemagick 在应用裁剪命令并单独处理每一帧时似乎没有考虑到这一点.-coalesce 重建完整的帧.
  • 其他命令将考虑原始 gif 中提供的偏移信息,因此您需要使用 -repage 0x0 强制重置该信息.
  • 裁剪本身很简单,分别提供了宽度、高度、x 偏移和 y 偏移.例如,以 50 = 40x30+50+0 的 x 偏移量裁剪 40 宽和 30 高.
  • Crop 不会移除它从图像中剪下的画布.在裁剪后应用 +repage 会做到这一点.
    • 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.
    • 这篇关于如何使用 ImageMagick 裁剪动画 gif?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆