In this blog post I will show you how to, in bulk, remove any color background to from any image.
- All of your images in one folder
How To Easily Install ImageMagick for Mac OSX
- First we install HomeBrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Then we install ImageMagick:
brew install ImageMagick
- Test that ImageMagick is installed by running the command
magick, which should give you output with usage instructions
Removing Backgrounds From Images In Bulk
Once we have ImageMagick installed, we can begin to remove solid background colors like magic!
Here’s the command we will be working with:
find . -type f -name "*.jpg" -print0 | while IFS= read -r -d $'\0' file; do convert -verbose "$file" -transparent white "$file.png"; done # Credit: http://www.vectorns.com/blog/technical-articles/18-how-to-remove-white-background-from-a-picture
To break this command down…
- First we are looking for all of the files with the extension .jpg. If you files have a different extension, just change that to whatever you need.
- Then we loop through all of the photos and convert white background to transparent
- At the same time of the loop, we convert the jpg file format to png (which support transparency)
The values in bold in my breakdown are the values that we can change. For example, let’s say we want to convert a black background to blue, we would run the following command:
find . -type f -name "*.jpg" -print0 | while IFS= read -r -d $'\0' file; do convert -verbose "$file" blue black "$file.png"; done
If you find that there are some remnants of the white background you may need to add fuzz to the command, so it will like like:
convert /Users/mike/Downloads/photo\ work/transparent/your.png -fuzz 20% -transparent white result.png
20% fuzz is a good place to start. Below are some example of how fuzz changes the output.
Original vs. Transparent Background (No Fuzz)
20% Fuzz vs 40% Fuzz