Page 1 of 1

Set a color % transparent?

Posted: 2017-01-05T10:02:00-07:00
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

Re: Set a color % transparent?

Posted: 2017-01-05T10:28:14-07:00
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

Re: Set a color % transparent?

Posted: 2017-01-05T13:45:09-07:00
by cfredman
Sweet! I will give that a try.

Thanks!

Re: Set a color % transparent?

Posted: 2017-01-05T13:57:52-07:00
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