image - 使用 ImageMagick 将 gif 动画的背景更改为透明,但帧重叠。怎么解决?

标签 image imagemagick gif transparent

我想将gif背景更改为透明,我使用ImageMagick的以下命令:

convert input.gif -transparent white output.gif

但是,输出有重影效果,后面的帧与前面的帧重叠。

//抱歉,我没有足够的声誉来发布我自己的图片。 一个例子在这里:http://tieba.baidu.com/p/1090763568

怎样才能让它们不重叠?或者换句话说,没有重影效果?

最佳答案

我认为“答案”是,对于您的目的来说,这是一个制作得很糟糕的动画。您可以使用 ImageMagick 看到动画由 12 帧组成,如下所示:

identify anim.gif

anim.gif[0] GIF 400x350 400x350+0+0 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[1] GIF 1x1 400x350+0+0 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[2] GIF 226x152 400x350+85+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[3] GIF 218x152 400x350+89+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[4] GIF 210x152 400x350+93+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[5] GIF 202x152 400x350+97+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[6] GIF 194x152 400x350+101+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[7] GIF 194x152 400x350+101+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[8] GIF 202x152 400x350+97+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[9] GIF 210x152 400x350+93+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[10] GIF 218x152 400x350+89+8 8-bit sRGB 256c 106KB 0.000u 0:00.000
anim.gif[11] GIF 226x152 400x350+85+8 8-bit sRGB 256c 106KB 0.000u 0:00.000

您可以将图像分割为其组成框架并使白色区域透明,如下所示:

convert anim.gif -transparent none frame-%02d.gif

-rw-r--r--   1 mark  staff      9777  4 May 11:11 frame-11.gif
-rw-r--r--   1 mark  staff      9732  4 May 11:11 frame-10.gif
-rw-r--r--   1 mark  staff      9681  4 May 11:11 frame-09.gif
-rw-r--r--   1 mark  staff      9835  4 May 11:11 frame-08.gif
-rw-r--r--   1 mark  staff      9533  4 May 11:11 frame-07.gif
-rw-r--r--   1 mark  staff      9479  4 May 11:11 frame-06.gif
-rw-r--r--   1 mark  staff      9986  4 May 11:11 frame-05.gif
-rw-r--r--   1 mark  staff      9907  4 May 11:11 frame-04.gif
-rw-r--r--   1 mark  staff     10070  4 May 11:11 frame-03.gif
-rw-r--r--@  1 mark  staff     10099  4 May 11:11 frame-02.gif
-rw-r--r--   1 mark  staff        43  4 May 11:11 frame-01.gif
-rw-r--r--@  1 mark  staff     15917  4 May 11:11 frame-00.gif

您还可以将所有帧剪辑在一起,如下所示:

convert anim.gif -transparent white miff:- | montage -tile 3x -frame 5 - montage.jpg

enter image description here

如果您尝试使用 background 的处理方法将帧放回一起,您将丢失仅出现在第一帧中的单词 welcome:

convert -dispose background frame-0* a.gif

enter image description here

如果您尝试在动画之前将第一帧与其他帧合成(因此您有“欢迎”),您将得到一个黑色幽灵,因为男孩和女孩角色也出现在第一帧中:

convert frame-00.gif frame-02.gif -geometry +85+8 -composite x.gif

enter image description here

我看到的唯一解决方案是将第一帧放入 Photoshop 中并删除男孩和女孩,然后重建动画...但话又说回来,我不是动画专家,现在所有帧都是 “摆在桌面上”,其他人也许可以告诉你一个更简单的方法。

关于image - 使用 ImageMagick 将 gif 动画的背景更改为透明,但帧重叠。怎么解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23275123/

相关文章:

java - 图像IO : gif to jpeg problem -> the image becomes pink

css - 根据其内容将图像附加到链接

python - 使用边缘检测和 scikit-image 在 Python 中去除背景/屏蔽

image - OpenCV:在图像上绘图

android - Android 的图像效果?

imagemagick - 在修改后的原始图像上合成克隆 - 需要第二个克隆?

python - 将 GIF 与音乐节奏同步导致持续时间比预期的要短

image - 将R中的图另存为GIF

java - 在java中压缩/缩小图像文件

php - 基于css3渐变设置用php生成图像?