Search code examples
imagemagickbackground-imagebackground-color

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.


Solution

  • 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.