This ImageMagick command will make an image's white areas transparent:
magick convert FILE.png -transparent "#ffffff" TRANSPARENT.png
Here are three alternatives:
magick convert FILE.png -transparent white TRANSPARENT.png
magick convert FILE.png -fuzz 4% -transparent white TRANSPARENT.png
magick convert FILE.png -fuzz 4% -transparent "#ffffff" TRANSPARENT.png
Here is how to reverse the effect:
magick convert -flatten TRANSPARENT.png FILE.png
For step-by-step instructions, please read on.
Let us start with a canvas:
Onto our canvas, let us superimpose an image:
The image's white background obscures much of our canvas. What if we wanted a transparent background?
The following instructions explain how to install ImageMagick on your PC and turn the image's white background transparent. Non-PC instructions (Mac OS X, iOS, Unix) are similar.
Step-by-step Instructions for PC
Time required: about 10 minutes
- Download and install ImageMagick. Go to the ImageMagick download page and install the release of your choice. If you are on a PC, it is easiest to use the Windows installer. Be sure to select the option "Add application directory to your system path" because it will be needed for the rest of the tutorial:
- Download the image. Right-click the image below. Save it to your folder of choice. For the tutorial, we will save it to the default folder: Downloads.
- Open the Windows command prompt. To bring up your command prompt, open your Windows Start menu and search for "command prompt". (Alternatively, hit WINDOWS+R and enter "cmd.exe".) You should see something like this:
- Navigate to your folder. Type this command into your Windows command prompt, then hit enter:
This command says, "Open the downloads folder."
cdstands for change directory. Indicently, as an alternative to typing commands, you can also paste commands into the command prompt using right-click.
- Run ImageMagick. Run this command inside your Windows command prompt:
magick convert orig-2.png -transparent "#ffffff" transparent.png
This command says, "Use
orig-2.png. Invoke the
-transparentoption so that all white pixels, which are all pixels which have the the hexidecimal color
#ffffff, become transparent. Name the new file
transparent.png." Dashes (-) are commonly used to specify as options within command-line programs. Check ImageMagick's documentation for more details about convert.
- Success. Check your folder. You should now see a file entitled "transparent.png." Here is the final product:
How did it go? You are invited to share your feedback and any further thoughts in the discussion below, and please do not hesitate to connect with me via my contact page.
Lots of software programs could have done this job. Why did we choose ImageMagick? While ImageMagick is free to use for a wide range of purposes, that is not the end of the story.
Our next post will discuss the question "Why ImageMagick?" Using this post as a case study, we will dive into some of the other available options. We will also explore some of the implications of choosing open source versus proprietary software.