Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace white background color with transparent of an image in ImageMagick?

I have an image in .jpg format with white background color. I want to remove the white background color to transparent in Imagemagick. I tried many ways but still the white background can not be removed. Can some one help me to solve this.

like image 402
NewUser Avatar asked Sep 14 '12 11:09

NewUser


People also ask

How do you add a transparent background to an image?

Click Picture Tools > Recolor > Set Transparent Color.


2 Answers

You cannot have transparent background colors in your JPEGs. The JPEG file format doesn't support transparency.

If you need transparent background, you need to convert the JPEG to

  • either PNG (high quality, filesize possibly larger than JPEG)
  • or GIF (in case you can tolerate low quality and a range of maximally 255 colors).

Example command:

convert  your.jpg  -transparent white  your.png 
like image 189
Kurt Pfeifle Avatar answered Sep 22 '22 01:09

Kurt Pfeifle


First, you need to convert the image format from .jpg to .png format, because JPEG does not support transparency. Then use this command:

convert image1.png -fuzz 20% -transparent white result.png

The -fuzz option allows the specified percentage deviation from the pure white colour to be converted to transparent as well. This is useful, for example, when your image contains noise or subtle gradients.

like image 27
NewUser Avatar answered Sep 26 '22 01:09

NewUser