如何在ImageMagick中用透明的图像替换白色背景颜色?

问题描述:

我的图像为 .jpg格式白色背景色。我想在 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.

首先,你需要转换图像格式来自 .jpg .png 格式,因为JPEG不支持透明度。然后使用此命令:

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

-fuzz 选项允许将纯白色的指定百分比偏差转换为透明。这很有用,例如,当您的图像包含噪点或细微渐变时。

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.