Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick - How do I flatten white levels to pure white?

I have a png image with a white background which I'd like to turn transparent. This is fairly simple with this command:

$ convert image.png -transparent white image-trans.png

However, if the white background is not completely white (i.e, #FFFFFF, rgb(255,255,255), etc), then this doesn't work well.

Is there a way to set reduce everything below a certain threshold to complete white? Thanks.

like image 404
sa125 Avatar asked Jul 16 '12 17:07

sa125


1 Answers

The commandline option you are looking for is

-white-threshold value{%}

So a command of

convert image.png \
  -white-threshold 90% \
  -transparent white \
   image-trans.png

Note: Order of the respective parameters is significant! (You want first to convert all the light-gray pixels to white, then all white pixels to transparent.)

Works for me with 'ImageMagick version 6.7.8-0 2012-07-12 Q16'...

like image 115
Kurt Pfeifle Avatar answered Sep 27 '22 22:09

Kurt Pfeifle