MagickCore Color Replacement

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
grendell
Posts: 7
Joined: 2016-11-28T23:36:42-07:00
Authentication code: 1151

MagickCore Color Replacement

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

Re: MagickCore Color Replacement

Post 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.
snibgo's IM pages: im.snibgo.com
grendell
Posts: 7
Joined: 2016-11-28T23:36:42-07:00
Authentication code: 1151

Re: MagickCore Color Replacement

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

Re: MagickCore Color Replacement

Post 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%?
snibgo's IM pages: im.snibgo.com
grendell
Posts: 7
Joined: 2016-11-28T23:36:42-07:00
Authentication code: 1151

Re: MagickCore Color Replacement

Post by grendell »

Oh man, I was using an opacity of 0 because I'm used to thinking in alpha values. Thanks again!
Post Reply