Page 1 of 1

how to transform the transparency into a precise colour

Posted: 2010-06-09T03:39:32-07:00
by lariost
Short presentation :

I'm using imagemagick since few years, but i think i'm still a beginner, i'm still discovering something, and i'm still in need of something new, and there are always so many ways to do it, that's just incredible !
And I adore too the command line ! It makes me think to my beloved computers : Oric, Amiga, old 386 with Ms-dos, the old time, the good souvenirs ...

Anyway, my question :

I like the operator -transparent, but i would like to make just the inverse, to change the transparency (1-255) into a defined color.

I've tried many things but i found nothing, i've tried with '-transparent-color' option and a GIF but without success.
I've tried also to manipulate the channel Alpha, with '-alpha' options, but i have'nt got no result.

I suppose there's a solution or certainly many, but I 've got not enough experience.

Does someone have an idea ?
Thanks for everything.

Re: how to transform the transparency into a precise colour

Posted: 2010-06-09T08:40:17-07:00
by snibgo
I don't understand what you want. Do you want all pixels that have a particular transparency (such as 23) to be changed to a particular opaque colour? Or do you want all pixels that have any transparency (ie alpha < 255) to be changed to a particular colour? Or something else?

Possibly useful documentation:
http://www.imagemagick.org/Usage/channels/#extract
http://www.imagemagick.org/Usage/basics/
http://www.imagemagick.org/Usage/color/

Re: how to transform the transparency into a precise colour

Posted: 2010-06-09T09:32:29-07:00
by fmw42
not sure which way you want it, so try

convert image -channel a -threshold 0 +channel -background red -flatten result

or

convert image -channel a -threshold 0 -negate +channel -background red -flatten result

or

convert image -channel a -negate -threshold 0 -negate +channel -background red -flatten result

or

convert image -channel a -negate -threshold 0 +channel -background red -flatten result

Re: how to transform the transparency into a precise colour

Posted: 2010-06-16T22:27:09-07:00
by lariost
Sorry not to have been very clear, I've tried also the different possibilities and the first one seems to be the most successfull for what i want !
Now i have to understand it.

Thank you for everything, it will help me a lot !

Re: how to transform the transparency into a precise colour

Posted: 2010-06-17T11:14:17-07:00
by fmw42
convert image -channel a -threshold 0 +channel -background red -flatten result
This thresholds the alpha channel of the image only (-channel a -threshold 0) so that it is transparent. Then it turns back on the other channels (+channel). Then it flattens the transparent image over a red image so that the transparent parts become opaque red.