Set Opacity, but retain transparent sections in image?

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
radiohead
Posts: 2
Joined: 2018-08-09T02:02:43-07:00
Authentication code: 1152

Set Opacity, but retain transparent sections in image?

Post by radiohead »

Version ImageMagick-7.0.8-Q16

I'm a Newbie, but have read and trying to comply with the board guidelines!

I have a pile of png's which have a coloured area upon a (fully) transparent background. I am trying to set the opacity of the coloured area so it is semi-transparent, but retain the transparent area as fully transparent.

I have tried this:
FOR %G IN (*.png) DO convert %G -alpha set on -channel a -evaluate set 68% batch\%G

It sets the Opacity correctly, BUT it also makes the transparent area opaque - you can see the problem most obviously when it is overlaid in a Google map like this: http://a-bc.co.uk/MCA/AL000288-SK11350032.html:

Does anyone have any ideas how to get this right? To recap I want an image like you see on the above website link, but the hazy white area needs to be totally transparent, but the green and yellow areas semi-opaque.

I don't mind if it has to be done in 2 or more stages - the main thing is that I don't have to manually do it on 2000 images!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Set Opacity, but retain transparent sections in image?

Post by snibgo »

radiohead wrote:-evaluate set 68%
This sets all the alpha values to 68%, whatever they were before. Instead, you can multiply them, eg to 0.68 times what they were before.

"-alpha" can't take two parameters. Use "set" or "on", but not both. Or do "-alpha set -alpha on" if you want to do both.

When you have "-channel X", I suggest you always have a "+channel" after the operations you want restricted to that channel.

So:

Code: Select all

FOR %G IN (*.png) DO convert %G -alpha set -channel a -evaluate multiply 0.68 +channel batch\%G
snibgo's IM pages: im.snibgo.com
radiohead
Posts: 2
Joined: 2018-08-09T02:02:43-07:00
Authentication code: 1152

Re: Set Opacity, but retain transparent sections in image?

Post by radiohead »

Genius!

I have no idea what most of that means - but it works which is all that matters at the moment! In slow time I'll try and read, digest and learn from your explanation.

A million thanks - well actually about 2000 thanks!
Post Reply