RMagick remove white background from image and make it transparent

Tom picture Tom · Oct 12, 2011 · Viewed 12.7k times · Source

I need to remove the white background from this image and make the background transparent. So it's just a black tick on the transparent background exported as a png.

e.g. Turn

enter image description here

Into

enter image description here

Any ideas?

Answer

Shaun picture Shaun · Oct 12, 2011

convert image.png -matte -fill none -fuzz 1% -opaque white result.png

Replaces anything white with transparency. The fuzz option includes anything that is almost-white.