BACK TO THE HOMEPAGE

Apr 12, 2023 1 min read

Imagemagick Fuzz Transparent

A quick tutorial on using Imagemagick to remove a background colour from images. The image file format needs to support transparency e.g. PNG.

NOTE: JPG doesnt support transparency, so it would be necessary to convert the file.

There is also this method Imagemagick transparency I find the option below to be a bit more flexible.

Remove background color

  1. Set the input file
NODE_TYPE // bash
input="old-white.png"
  1. Set the output file
NODE_TYPE // bash
output="new-image.png"
  1. Set the background color to remove
NODE_TYPE // bash
background_color="white"
  1. Set the background to transparent and remove the colour white
NODE_TYPE // bash
convert $input -fuzz 5% -transparent $background_color $output 

In the above example the input image has a white background. Amend the percentage as required.

NOTE: Hex codes can also be used for the background_color parameter

NODE_TYPE // bash
background_color="#ffffff"