Batch Image Processing in Linux – Resizing, Enhancing

I was always looking for some sort of tool like IrfanView (Windows) which can do batch processing for images on Linux box. Finally I wrote a small, simple script capable of batch processing. This simple bash script does batch resizing & enhancing for images.
Program parameters asks for Source_Directory & Destination_Directory. And based on the ImageMagik software they perform different operations on Images.
The file is attached as a text document. Just rename it to filename.bash before executing it. Bash Script: Batch Image Resizing
Here is the snippet of simple shell script.


#!/bin/bash
# This script does Batch resizing of the Photographs
# It requires ImageMagick*.* image editing software
# http://www.imagemagick.org/script/index.php
# Author: Ruituraj A. Gandhi
# Version 1.0
# Shared under Creative Commons Attribution-Share Alike 3.0 United States License
# Program Parameters
echo "Running Image enhancing & resizing script based on ImageMagik software.\n"
echo "Please enter the full Source & Target directory path for Images respectively:\n"
read BASE_DIR OUTPUT_DIR
echo "The base directory is: ${BASE_DIR}, the output directory is: ${OUTPUT_DIR}\n"
# Default base directory path where images are located
DEFAULT_BASE_DIR=`pwd`


# Output directory for images
DEFAULT_OUTPUT_DIR="${DEFAULT_BASE_DIR}/Resized_Images"
# Search if IMAGEMAGIK software is installed on the sytem
SEARCH_IMAGEMAGIK=`rpm -qa | grep -i ImageMagick*.* | wc -l`
if [ $SEARCH_IMAGEMAGIK -eq 0 ]; then
echo "The ImageMagik not found on the system.\n";
echo "Program will exit. \n"
else
echo "Image Magik software found on the system.\n"
echo "Resizing & Enhancing the images in ${BASE_DIR}.\n"
if [ -z "$BASE_DIR" ]; then
BASE_DIR=${DEFAULT_BASE_DIR}
echo  "The default base directory is: ${BASE_DIR}\n"
fi
if [ -z "$OUTPUT_DIR"]; then
echo "Creating new output directory ${DEFAULT_OUTPUT_DIR}\n"
mkdir ${DEFAULT_OUTPUT_DIR}
OUTPUT_DIR=${DEFAULT_OUTPUT_DIR}
echo "The defualt output directory is: ${OUTPUT_DIR}\n"
fi
cp ${BASE_DIR}/* ${OUTPUT_DIR}/
# Remove spaces from Filenames & Replace with underscore
for file in ${OUTPUT_DIR}/*.jpg
do
echo "Removing spaces for \n" ${file}
mv "${file}" "`echo ${file} | sed "s/ /_/g"`"
done
for file in ${OUTPUT_DIR}/*.jpg
do
echo "The image being processed is: ${file}\n"
mogrify -verbose -enhance -normalize -type truecolor -resize 1600X1600 ${file}
echo "Images resized to 1600X1600"
done
fi