Setting an image to 50% transparency

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

Setting an image to 50% transparency

Post 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
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Setting an image to 50% transparency

Post 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
User avatar
rossmcm
Posts: 28
Joined: 2012-07-26T06:10:38-07:00
Authentication code: 15
Location: Auckland, NZ

Re: Setting an image to 50% transparency

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Setting an image to 50% transparency

Post 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.
Post Reply