Page 1 of 1
replace all one color with another including partial transp.
Posted: 2012-10-14T13:31:41-07:00
by rossmcm
I have a PNG image with a shape that is all one color, but the edges of the shape have partially transparent pixels where anti-aliasing has been used to smooth the edges.
When I use the -fill option to replace all of the color by another
Code: Select all
convert 1.png -fill red -opaque black 2.png
only the pixels with 100% opacity are replaced, leaving the partially transparent edges with the original color.
How do I convert all of the pixels of that color, so that a partially transparent black pixel becomes a partially transparent red pixel.
This has to be a common requirement, but Google hasn't found anything for me.
TIA,
R
Re: replace all one color with another including partial tra
Posted: 2012-10-14T14:04:40-07:00
by fmw42
First you background image is not all black, there are some white lines in it. To avoid problems of the white showing, this seems to work by making the whole background red.
convert 1.png -alpha off -fill red -colorize 100 -alpha on 4.png
The following also works if you want to keep your white lines in the background and just change the black parts to red
convert 1.png -alpha off -fill red -opaque black -alpha on 5.png
Re: replace all one color with another including partial tra
Posted: 2012-10-14T14:50:51-07:00
by rossmcm
Code: Select all
convert 1.png -alpha off -fill red -opaque black -alpha on 5.png
worked fine thanks. I'm baffled by your comment that the PNG contains white lines. I certainly can't see them with Gimp.
Re: replace all one color with another including partial tra
Posted: 2012-10-14T15:11:48-07:00
by fmw42
rossmcm wrote:Code: Select all
convert 1.png -alpha off -fill red -opaque black -alpha on 5.png
worked fine thanks. I'm baffled by your comment that the PNG contains white lines. I certainly can't see them with Gimp.
convert 1.png -alpha off 1_aoff.png
That will remove the transparency so you can see the background image.
You can also see that from
convert 1.png -verbose info:
by looking at the histogram
idv 1.png
Image: 1.png
...
Histogram:
350: ( 0, 0, 0,255) #000000 black
325: ( 0, 0, 0, 0) #00000000 none
28: ( 0, 0, 0,159) #0000009F srgba(0,0,0,0.623529)
321: (255,255,255, 0) #FFFFFF00 srgba(255,255,255,0)
These are white pixels with full transparency.
Re: replace all one color with another including partial tra
Posted: 2012-10-14T16:05:13-07:00
by rossmcm
Aha!... I see now. A bit of image swarf. Many thanks for your assistance.