Page 1 of 1

Setting an image to 50% transparency

Posted: 2017-03-09T18:38:04-07:00
by rossmcm
I'm having difficulty using IM to partially fade an image. Image1 has a fully transparent background, fully opaque foreground and a drop shadow:
Image
I want to achieve the same effect as shown in Image2. I made image2 by loading Image1 into GIMP and setting the opacity to 50% and exporting a PNG from the result:
Image

with IM I tried this (based on an answer I saw on this forum - I'm not sure exactly what the parameters mean):

Code: Select all

convert image1.png -alpha set -channel Alpha -evaluate set 50% png32:image3.png
Heres the result:
Image

I'm having a similar issue when I try to perform the effect in Delphi code. The routine is from a library and seems to work by filling the alpha channel in the PNG with the 50% opacity value of 128, but the resulting image suffers from the same problem. This leads me to think that the original image (constructed with GIMP) has issues maybe.

Any comments appreciated.

Version: ImageMagick 6.9.0-0 Q16 x64 2014-11-14 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates (built-in): bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsvg tiff webp xml zlib
Windows 10

Re: Setting an image to 50% transparency

Posted: 2017-03-09T19:45:29-07:00
by GeeMack
rossmcm wrote: 2017-03-09T18:38:04-07:00I want to achieve the same effect as shown in Image2. I made image2 by loading Image1 into GIMP and setting the opacity to 50% and exporting a PNG from the result:
Image
I get the result you're trying to get using ImageMagick 6.9.7-6 on Windows 10 64 and running this command on your image...

Code: Select all

convert Image1.png -alpha set -background none -channel A -evaluate multiply 0.5 +channel result.png

Re: Setting an image to 50% transparency

Posted: 2017-03-09T22:55:32-07:00
by rossmcm
Hey, so do I ! BRILLIANT!

Many thanks for that. Would you mind outlining what my attempt was doing (or not doing)? I'm still faced with fixing the library routine to implement the same thing.

Re: Setting an image to 50% transparency

Posted: 2017-03-09T23:26:29-07:00
by fmw42
You set the whole image transparency to 50% everywhere (including where it was fully transparent) using -evaluate set 50%. GeeMack simply reduce all transparency by half via -evaluate multiply 0.5, so that fully opaque became half transparent, etc, but full transparent stayed fully transparent.