How to convert color to transparency using ImageMagick

You can use ImageMagick to convert a given color to transparency:

convert in.png -fuzz 10% -transparent #ffffff out.png

The fuzz parameter tells ImageMagick to also convert colors within a 20% tolerance range to alpha. This is especially important for JPEG images containing compression artifacts, i.e. pixels that are not purely white. In practice, you’ll often need to play around with the fuzz parameter to select the right value.

Example:

Applied to the following image:

using

convert Transparency-example.png -fuzz 10% -transparent #ffffff out.png

you’ll generate a out.png like this: