Replace white with transparent?
Replace white with transparent?
Is there a way to have IM replace the color #ffffff with transparent over an entire image (non-contiguous) ?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Replace white with transparent?
convert inputimage -transparent white outputimage
or
convert inputimage -transparent "#ffffff" outputimage
or
convert inputimage -transparent "#ffffff" outputimage
Re: Replace white with transparent?
Thanks, it worked partially. I had to save as a gif for the transparency to save which is no big deal but the transparency is badly pixelated around the image edges. Is there a way to soften this or match the #ffffff less strictly?
Thanks again.
Thanks again.
Re: Replace white with transparent?
Or is there a way to convert an image to something with clean edges, like line art, that can then be used with background transparency so it shows cleanly when displayed on a dark canvas?
Re: Replace white with transparent?
Check the -fuzz option.
Re: Replace white with transparent?
I am unclear of what the distance value should be. Any advise?rmagick wrote:Check the -fuzz option.
Re: Replace white with transparent?
I advise trial and error.
Re: Replace white with transparent?
I don't even know where to begin. What is a distance from #ffffff and what would be a distance increment from the first example distance?
Re: Replace white with transparent?
I don't either, so if I were doing this, I'd try -fuzz 50. If that didn't help, I'd try -fuzz 500. Not enough? -fuzz 5000. Eventually you'll find some number that is either perfect or too big. If it's too big, try something halfway between too big and not enough.
-fuzz 50 - not enough
-fuzz 500 - too big
-fuzz 250 - too big
-fuzz 125 - pretty close
-fuzz 100 - not enough
-fuzz 112 - on the money!
-fuzz 50 - not enough
-fuzz 500 - too big
-fuzz 250 - too big
-fuzz 125 - pretty close
-fuzz 100 - not enough
-fuzz 112 - on the money!
Re: Replace white with transparent?
Thanks. I didn't know if the distance was set as simply as that or if it was a matrix or other complex math equation.
Re: Replace white with transparent?
The fuzz option accepts percent values as well, for example, -fuzz 15%.
Re: Replace white with transparent?
Thanks. I found an acceptable fuzz percentage.
Your help is appreciated.
Your help is appreciated.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Replace white with transparent?
The highly pixelated is a result of two things.
First you are replacing pure white with transparent. No semi-transparent pixels will be generated to smooth the edges or make it cleaner looking.
See IM examples, Channels, Masks and Transparency,
Transparency Masking an Image
http://imagemagick.org/Usage/channels/#mask_creation
Secondly GIF can not handle semi-transparency, so even if you create a nice clean looking edge using semi-transparent pixels, it will still come out horible, unless you smooth those semi-transparent pixels with a color close to the intended backgound the image will be used on.
See IM examples Common Image Formats, GIF,
GIFs on a solid color background
http://imagemagick.org/Usage/formats/#bgnd
First you are replacing pure white with transparent. No semi-transparent pixels will be generated to smooth the edges or make it cleaner looking.
See IM examples, Channels, Masks and Transparency,
Transparency Masking an Image
http://imagemagick.org/Usage/channels/#mask_creation
Secondly GIF can not handle semi-transparency, so even if you create a nice clean looking edge using semi-transparent pixels, it will still come out horible, unless you smooth those semi-transparent pixels with a color close to the intended backgound the image will be used on.
See IM examples Common Image Formats, GIF,
GIFs on a solid color background
http://imagemagick.org/Usage/formats/#bgnd
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/