how to transform the transparency into a precise colour

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
lariost

how to transform the transparency into a precise colour

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: how to transform the transparency into a precise colour

Post 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/
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to transform the transparency into a precise colour

Post 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
lariost

Re: how to transform the transparency into a precise colour

Post 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 !
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: how to transform the transparency into a precise colour

Post 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.
Post Reply