Mixed Opacity

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
karlos
Posts: 2
Joined: 2014-09-18T06:05:09-07:00
Authentication code: 6789

Mixed Opacity

Post by karlos »

Hi,
Complete newbie here struggling ...
I have an image which is 100% opaque.
I would like to convert black to 0% alpha ie fully transparent and all other colours to 50%

This is as far as I managed:
convert 41.png -channel Alpha -evaluate set 50% -transparent black 41c.png

but this creates 0% black alpha and everything else resorts to 100%.

Preferrably as I'm running against lots of images I'd like to do this in one step.

Many thoughts greatfully received
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Mixed Opacity

Post by snibgo »

"-transparent black" ensures that the image has an enabled alpha channel. (See http://imagemagick.org/script/command-l ... ransparent ). But "-channel Alpha -evaluate set 50%" doesn't so, if the image doesn't have an alpha, this will have no effect.

The other issue is that "-transparent black" won't convert pixls that aren't opaque.

So I would do it in the opposite order:

Code: Select all

convert 41.png -transparent black -channel Alpha -evaluate multiply 0.5 +channel 41c.png
After "-transparent black", some pixels have alpha=0 and others have alpha=100%. So multiplying all alphas by 0.5 (or dividing by 2) will do what you want.

"+channel" is good practice after "-channel". It makes all subsequent operations apply to the normal channels. It isn't strictly needed in this particular case.
snibgo's IM pages: im.snibgo.com
karlos
Posts: 2
Joined: 2014-09-18T06:05:09-07:00
Authentication code: 6789

Re: Mixed Opacity

Post by karlos »

absolutely perfect - thankyou very much
Post Reply