How to Make an Image's Background Transparent?
February 23, 2018
You probably have already downloaded once an image with a white background, such as this one (the grey area around the logo just serves the purpose of seeing the white background).

For a number of reasons, one could want to have the same image with a transparent background. Luckily, ImageMagick has our back covered once more.
If you haven’t already, install ImageMagick:
brew install imagemagick
Even though installed as imagemagick
, there is no imagemagick
command. Instead, many separate commands are defined for different use cases. Today, we’ll use the convert
command.
With ImageMagick installed, the easiest way to remove the white background is to use the following command:
convert test.png -transparent white transparent.png
The command is very simple: we pass an input and output files and the -transparent
option is used to select the color we want to make transparent which can be passed as a color name or in hex/RGB format. Of course, you should choose an output format which handles transparency, such as PNG. The input can be in any format though.
Trying this command with our image from above gives the following. This looks fine, however if we look more closely we’ll see that not all white parts have been removed.


The -fuzz
option can help us here. It simply matches colors that are within x percents of the intensity of the target color. In most cases, 2% is a reasonable value.
convert test.png -fuzz 2% -transparent white transparent.png
Voilà!

