Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a semi-transparent PNG with ImageMagick/convert

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

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

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

The first example results in an error,

$ /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

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 version is 6.8.0-4)

like image 404
user1502835 Avatar asked Nov 13 '12 18:11

user1502835


1 Answers

Resolution has been found:

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

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

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.

like image 59
user1502835 Avatar answered Sep 19 '22 04:09

user1502835