Set a color % transparent?

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
cfredman
Posts: 2
Joined: 2017-01-05T08:14:32-07:00
Authentication code: 1151

Set a color % transparent?

Post by cfredman »

Hi,

I've searched the web and documentation at length looking for an answer to this, but I haven't been able to find an answer that fits exactly.

I'm wondering if it is possible with 7.0.4-0 Q16 x64 (or any other version of IM) to set a specific color to a percentage of transparent (or opaque, I suppose)? This would be so that I could do a gradient fade to transparent at the same time it fades in color.

Imagine an eps with solid black lines and a white background. I'm converting them to png's where white needs to be fully transparent and black fully opaque. No problem, except -

Now imagine that some of these images have a round gradient in them somewhere that fades from black to white (looks like a 3D ball.) Can I set the various intermediate colors in the gradient to percentages of transparent? Something like this (which I know isn't valid), for example?

-transparent #cccccc 50% -transparent #fefefe 10% etc.

Or is there a more simple or direct way to do it that I've totally missed?

Thanks!
cfredman
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Set a color % transparent?

Post by snibgo »

You can clone the image and copy the opacity. Then any pixels that were black will become transparent, white will remain opaque, 25% gray will be 25% opaque, etc.

Code: Select all

magick in.png ( +clone ) -compose CopyOpacity -composite out.png
snibgo's IM pages: im.snibgo.com
cfredman
Posts: 2
Joined: 2017-01-05T08:14:32-07:00
Authentication code: 1151

Re: Set a color % transparent?

Post by cfredman »

Sweet! I will give that a try.

Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Set a color % transparent?

Post by snibgo »

Sorry, I've just noticed: "white needs to be fully transparent and black fully opaque". So you'll need to negate:

Code: Select all

magick in.png ( +clone -negate ) -compose CopyOpacity -composite out.png
snibgo's IM pages: im.snibgo.com
Post Reply