Hey all,
i have searched throu this forum for the answer to this, but have not found one that works for me.
I have a couple hundred images that are gif, The image is of a circle on transparent background. There is other color stuff in the circle. My question is, how to i replace the white with transparency so i can overlay the image on another image on a website?
thanks for any tips
replace white with transparency
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: replace white with transparency
nephish wrote:Hey all,
i have searched throu this forum for the answer to this, but have not found one that works for me.
I have a couple hundred images that are gif, The image is of a circle on transparent background. There is other color stuff in the circle. My question is, how to i replace the white with transparency so i can overlay the image on another image on a website?
thanks for any tips
try
convert image.gif -transparent white result.gif (or use result.png)
or if not perfectly white, then try
convert image.gif -fuzz XX% -transparent white result.gif
where the smaller the %, the closer to true white or conversely, the larger the %, the more variation from white is allowed to become transparent.
http://www.imagemagick.org/script/comma ... ransparent
http://www.imagemagick.org/script/comma ... s.php#fuzz
Re: replace white with transparency
that is what i needed, the fuzz made a difference.
thanks very much.
thanks very much.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: replace white with transparency
I have said this again and again.
Unless you are saving to GIF, using a color replacement with a fuzz factor is NOT a good way to change background to transparency. So unless the result is GIF, or the image has a limited palette (rare these days) don't use it!
The alternatives to this are however many, and varied, and often complex. It all depends on exactly the type of image and the edge effects that is involved.
A black edged object on a white background however should be simple to solve. by using a mask of 'what is fully-opaque' and the new -alpha shape operator.
I have NOT yet created an example of this simple case. Though the recent discussion on double masking methods is very close to this.
Unless you are saving to GIF, using a color replacement with a fuzz factor is NOT a good way to change background to transparency. So unless the result is GIF, or the image has a limited palette (rare these days) don't use it!
The alternatives to this are however many, and varied, and often complex. It all depends on exactly the type of image and the edge effects that is involved.
A black edged object on a white background however should be simple to solve. by using a mask of 'what is fully-opaque' and the new -alpha shape operator.
I have NOT yet created an example of this simple case. Though the recent discussion on double masking methods is very close to this.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: replace white with transparency
thank you fmw42,
I tried '-transparent white' in my image , still some spots were left which were not exactly white . Then I added -fuzz 10% . Voila , I got what I wanted .
I tried '-transparent white' in my image , still some spots were left which were not exactly white . Then I added -fuzz 10% . Voila , I got what I wanted .
Re: replace white with transparency
Thanks Anthony.
Could you suggest what is the best sequence to make background transparency for this image?
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: replace white with transparency
Compare it with a white image, and generate a mask, with anti-aliased transparent edges...
See http://www.imagemagick.org/Usage/masking/#semi-trans
Though it is simpler as the background is just white.
Basically work out what IS fully-opaque (foreground), and you know what is fully-transparent (background - white), and then try to work out appropriate alpha value and it corrected color, for the pixels that lie between the two parts. For sharp edges like this the color correction will typically the color of the nearest opaque pixel (simple morphology), so that is easy. Its working out the inside-outside and alpha values that is hard. See the example linked.
Of course it would be better if you can generate that gradient basied on the average color at each of the edge areas, though that would be difficult and may not be worth the effort.
I look forward to seeing what people on this forum come up with!
See http://www.imagemagick.org/Usage/masking/#semi-trans
Though it is simpler as the background is just white.
Basically work out what IS fully-opaque (foreground), and you know what is fully-transparent (background - white), and then try to work out appropriate alpha value and it corrected color, for the pixels that lie between the two parts. For sharp edges like this the color correction will typically the color of the nearest opaque pixel (simple morphology), so that is easy. Its working out the inside-outside and alpha values that is hard. See the example linked.
Of course it would be better if you can generate that gradient basied on the average color at each of the edge areas, though that would be difficult and may not be worth the effort.
I look forward to seeing what people on this forum come up with!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/