Page 1 of 1

MagickCore Color Replacement

Posted: 2016-11-30T20:30:25-07:00
by grendell
On the CLI, I'm using the following to replace all white pixels with transparency:

Code: Select all

convert input.png -transparent white output.png
What would the equivalent be with MagickCore? I'm currently using ImageMagick 6.9.6-6 on OSX 10.9.5.

I'm not quite sure how to even search for this. Thanks in advance!

Re: MagickCore Color Replacement

Posted: 2016-11-30T20:53:10-07:00
by snibgo
grendell wrote:I'm not quite sure how to even search for this.
The answer to that is: grep the source code. Start by grepping just magick\*.h, for "transparent", any case. Scan down the short list, looking for a possible candidate. "TransparentPaintImage(" in paint.h looks promising, so examine that function in paint.c. Yes, that looks good.

Re: MagickCore Color Replacement

Posted: 2016-11-30T22:44:46-07:00
by grendell
Ah, thanks! For whatever reason, I didn't realize that -transparent was the command. That makes total sense now.

Unfortunately, this doesn't seem to be working because my Image doesn't have an alpha channel. When I write it to disk, it comes out as grayscale. I've tried SetImageAlphaChannel() and SetImageType() without success. Any suggestions? Thanks again.

Re: MagickCore Color Replacement

Posted: 2016-11-30T23:27:34-07:00
by snibgo
Sorry, I am hopeless at debugging code I can't see.

TransparentPaintImage() calls SetImageAlphaChannel() if needed, so that should be ok. Are you setting the parameters correctly? What "opacity" value are you using, and is that correct? With a large fuzz value, eg 100%?

Re: MagickCore Color Replacement

Posted: 2016-11-30T23:41:27-07:00
by grendell
Oh man, I was using an opacity of 0 because I'm used to thinking in alpha values. Thanks again!