Shell Bash Script to Remove Background From PNG,JPEG Images on Command Line Full Project For Beginners



for img in "src"/*
	echo "checking $img"
	if [ "${img: -4}" == ".png" ]; then
		name=$(basename $img .png)
		echo "converting $img"
		convert $img -transparent $background_color out/$name-nobg.png




bash script to remove background from images

This script uses ImageMagick libraries to convert images.

How to use

To use this script, create a folder “src” where to put all the original images. Note that this works only if the source images are in .png format!

Then create an “out” folder where the converted images will be located. The script will take all the images in src folder, convert them and put into out folder. The two folders need to be at the same level of the script.

Simply run the script and enjoy!


  • pass backgorund color as a parameter
  • pass src and out folder as a parameter

Leave a Reply