ImageMagick: How to Make a Transparent Background

Updated

Learn how to remove a background and make it transparent using ImageMagick

ImageMagick: How to Make a Transparent Background

Before we start, make sure you have ImageMagick installed on your computer and your image ready in a folder. If you don't have it yet, run this command:

brew install imagemagick

First, open your terminal and navigate to the folder that has your image. To make the white background transparent, run this command:

magick input.jpg -fuzz 10% -transparent white output.png

The -transparent white option clears every white pixel, and -fuzz 10% also catches near white shades, so the edges come out clean. Raise the fuzz value if some white is left behind. Save the result as a .png, because a .jpg can't be transparent.

If your subject has white in it too, run this command instead:

magick input.jpg -alpha set -fuzz 10% -fill none -floodfill +0+0 white output.png

The -floodfill +0+0 white option starts at the top left corner and only clears the white connected to it, so white inside your subject stays. The -alpha set option turns on the transparency channel, and -fill none is the transparent paint. To make sure everything worked, run open output.png and check the result.

One more tip: you can clear any color, not just white. Replace white with another color name or a hex code like "#00FF00".