Hello,
There is a 2 color image (text + background) PNG and it is necessary to replace background color (white) to transparent. How is it possible to do in magick core c api?
Thanks
replace color to transparent
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: replace color to transparent
It's easier to do this with MagickWand. See the third and fourth examples in my MagickWand Examples in C.
A floodfill may not do what's required if there are "islands" of background colour which must also be replaced. In that case you would use MagickTransparentPaintImage.
Pete
A floodfill may not do what's required if there are "islands" of background colour which must also be replaced. In that case you would use MagickTransparentPaintImage.
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
See my message in this topic for a link to a zip of all the files.
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: replace color to transparent
I've added a fifth example to the examples which shows how to use MagickTransparentPaintImage to target all white pixels.
Pete
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
See my message in this topic for a link to a zip of all the files.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: replace color to transparent
As it is a gradient of two colors. this is easy.
first normalize or contrast-stretch the image to black and white. Then negate if needed to make opaque = white, black = transparent. now just run -background {color} -alpha shape the background color will be the shapes color and everything else will be transparent, or semi-transparent.
See http://www.imagemagick.org/Usage/basics/#alpha
ASIDE the above is equivelent to using CopyOpacity and re-seting the colors.
This is a LOT better than just making pure or near-pure white perfectly transparent! Though does not work well for GIF image saves.
You may also like to look at +level-colors if you just want to assign a new colors to black and white and have the gradient work out right.
first normalize or contrast-stretch the image to black and white. Then negate if needed to make opaque = white, black = transparent. now just run -background {color} -alpha shape the background color will be the shapes color and everything else will be transparent, or semi-transparent.
See http://www.imagemagick.org/Usage/basics/#alpha
ASIDE the above is equivelent to using CopyOpacity and re-seting the colors.
This is a LOT better than just making pure or near-pure white perfectly transparent! Though does not work well for GIF image saves.
You may also like to look at +level-colors if you just want to assign a new colors to black and white and have the gradient work out right.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/