使用ImageMagick/convert创建一个半透明的PNG [英] Creating a semi-transparent PNG with ImageMagick/convert

查看:697
本文介绍了使用ImageMagick/convert创建一个半透明的PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有PNG文件,我想将整个图像转换为半透明.

I have PNG files that I would like to convert the whole image to be semi-transparent.

该图像将在KML文件中作为图标叠加层引用,以供在Google地球/地图中使用.

The image will be referenced in a KML file as an icon overlay for use in Google Earth/Maps.

以下示例是使用ImageMagick的 convert 命令向我建议的,但是似乎都没有用.

The following examples have been suggested to me using the ImageMagick convert command, however neither seems to work.

第一个示例导致错误

$ /usr/local/bin/convert 121112142121.png -channel Alpha -evaluate Set 50% 2121112142121.png
convert: no decode delegate for this image format '121112142121.png' @ error/constitute.c/ReadImage/550.
convert: option requires an argument '-evaluate' @ error/convert.c/ConvertImageCommand/1400.

第二个无法对图像进行任何可见的更改:

the second fails to make any observable change to the image:

convert filename.png -fill '#00000080' -draw 'matte 100,100 reset' output.png

虽然我在网上可以找到许多示例,这些示例可以从特定的颜色或Alpha蒙版创建完全透明的图像,但似乎找不到能够创建半透明图像或更改不透明度的任何示例.我想找到一种使用convert命令或ImageMagick Perl做到这一点的方法.

While I can find many examples on the web for creating fully transparent images from specific colors or alpha masks, I cannot seem to find any that work for creating semi-transparent images or changing the opacity. I would like to find a way to do this with the convert command, or with ImageMagick Perl.

(ImageMagick版本为6.8.0-4)

(ImageMagick version is 6.8.0-4)

推荐答案

已找到解决方案:

convert input.png -alpha set -channel A -evaluate set 50% output.png

以上命令使整个图像(所有颜色)半透明.

The above command makes the entire image (all colors) semi-transparent.

我遇到的另一个问题是ImageMagick的最新版本是从源代码编译的,没有安装所有最新的图像库(特别是libpng).请密切注意configure的输出,以确保从源代码编译时找到libpng.似乎还早于6.6的ImageMagick版本和/或更早的libpng版本可能不支持透明的png生成.

Another problem I had was that the latest version of ImageMagick was compiled from source without all the most recent image libraries installed (in particular libpng). Pay close attention to the output of configure to ensure libpng is found if compiling from source. It also appears that versions of ImageMagick earlier than 6.6 and/or older versions of libpng may not support transparent png generation.

这篇关于使用ImageMagick/convert创建一个半透明的PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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