image - 如何使图像背景透明?

标签 image imagemagick

我有两张图片:

First

http://www.eurocopter.in/contest/images/loader33.gif

Second



如果您会看到第一张图像没有背景。所以背景看起来是白色的。第二张图片有黑色背景。

  • 问题 1:我们所说的第一类图片是什么?
  • 问题2:如何制作这种类型的图片?
  • 问题三:如何将第二种图片转换成第一种图片?
  • 最佳答案

    它们是动画 GIF,第一个具有透明背景。您可以使用 ImageMagick(安装在大多数 Linux 发行版上,可免费用于 OSX 和 Linux)将图像分成单独的帧,如下所示:

    convert -coalesce type1.gif frame%02d.gif
    

    这将为您提供以下 18 帧作为单独的图像
    frame00.gif frame04.gif frame08.gif frame12.gif frame16.gif
    frame01.gif frame05.gif frame09.gif frame13.gif frame17.gif
    frame02.gif frame06.gif frame10.gif frame14.gif
    frame03.gif frame07.gif frame11.gif frame15.gif
    

    frame00.gif

    enter image description here

    如果将它们制作成这样的蒙太奇,您可以一次看到它们:
    convert -coalesce type1.gif miff:- | montage -tile x4 -frame 5 - montage.gif
    

    enter image description here

    您可以找到有关每个帧的信息,例如它的大小,如下所示:
    identify type1.gif
    
    type1.gif[0] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[1] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[2] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[3] GIF 100x100 100x100+0+0 8-bit sRGB 64c 29.2KB 0.000u 0:00.000
    type1.gif[4] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[5] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[6] GIF 100x100 100x100+0+0 8-bit sRGB 64c 29.2KB 0.000u 0:00.000
    type1.gif[7] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[8] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[9] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[10] GIF 100x100 100x100+0+0 8-bit sRGB 64c 29.2KB 0.000u 0:00.000
    type1.gif[11] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[12] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[13] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[14] GIF 100x100 100x100+0+0 8-bit sRGB 64c 29.2KB 0.000u 0:00.000
    type1.gif[15] GIF 100x100 100x100+0+0 8-bit sRGB 64c 29.2KB 0.000u 0:00.000
    type1.gif[16] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    type1.gif[17] GIF 100x100 100x100+0+0 8-bit sRGB 128c 29.2KB 0.000u 0:00.000
    

    您可以像这样将所有框架重新组合在一起:
    convert frame* -loop 0 -delay 20 anim.gif
    

    enter image description here

    您可以尝试使用这样的命令从第二个中删除黑色背景,使其更像第一个。您可能需要摆弄 fuzz因素一点:
    convert type2.gif -fuzz 15% -transparent black new.gif
    

    enter image description here

    关于image - 如何使图像背景透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29821066/

    相关文章:

    javascript - 将类(class)名称从 child 转移到 parent

    php - 想象一下。将颜色更改为透明

    php - 在php中使用shearImage函数时透明变黑

    linux - 如何大量使用转换命令,一个干净的正则表达式扫描?

    javascript - 对鼠标悬停的图像部分进行取消模糊处理

    javascript - 将图像填充到 Canvas 中

    r - 由 ggplot 制作的 autocrop 分面图

    android - Android 应用程序的图像大小

    ruby-on-rails - Brew与ImageMagick链接

    perl - 如何使用 Image::Magick 调整图像大小以适合区域?