Here is another script I found on the internet, made some modifications and am positing here for your use and enjoyment. Originally written by Dawid Michalczyk, it consisted of three separate script files for three graphic conversions. I have modified it to support five types and really it could support a lot more, you need only try it to see.
To use convert2 copy and past the following text into a file in your home area bin folder as the file convert2 (~/bin/convert2).
#!/bin/bash
#: Title : Convert2
#: Date Created: Fri Oct 8 21:29:50 CDT 2010
#: Last Edit : Sat Oct 21 17:37:00 CDT 2010
#: Author : Dawid Michalczyk & J. McDaniel
#: Version : 1.00
#: Description : Convert image file from/to - bmp png jpg gif pdf - format
#: Options : Convert2 [type] -vhlr] <file> [file...]
# Created for the openSUSE Forums on Thursday October 21th, 2010
# Copy and paste this text into a file called convert2 in your home ~/bin folder
# To Make this script executable run the terminal command chmod +x ~/bin/convert2
# #############################################################################
NAME_="Convert2"
PURPOSE_="Convert image file from/to - bmp png jpg jpg pdf - format"
SYNOPSIS_="$NAME_ [type] -vhlr] <file> [file...]"
REQUIRES_="standard GNU commands, ImageMagick"
VERSION_="1.00"
IMAGES_="bmp png jpg gif pdf"
# #############################################################################
# This program is distributed under the terms of the GNU General Public License
#
# Display Help If requested
#
usage () {
echo
echo >&2 "$NAME_ $VERSION_ - $PURPOSE_
Usage: $SYNOPSIS_
Requires: $REQUIRES_
Type: bmp, png, jpg, gif or pdf: default Type is jpg
Options:
-r, remove the input file after conversion
-v, verbose
-h, usage and options (this help)
-l, see this script,, use Q to quit"
echo
exit 1
}
#
# args check - Did we get any commands
#
echo
$# -eq 0 ] && { echo >&2 missing argument, type $NAME_ -h for help; exit 1; }
#
# Check for Image Type for conversion - Default will be jpg if not specified
#
TYPE=$1
if "$IMAGES_" == *$TYPE* ]] ; then
shift
else
TYPE=jpg
fi
#
# varible setup
#
rm_input=
verbose=
#
# option and argument handling
#
while getopts vhlr options; do
case "$options" in
r) rm_input=on ;;
v) verbose=on ;;
h) usage ;;
l) less $0; exit 1 ;;
\?) echo invalid argument, type $NAME_ -h for help; exit 1 ;;
esac
done
shift $(( $OPTIND - 1 ))
#
# check if required command is in $PATH variable
#
which mogrify &> /dev/null
$? != 0 ]] && { echo >&2 the required ImageMagick \"mogrify\" command \
is not in your PATH variable; exit 1; }
#
# main progrm execution starts here
#
for a in "$@"; do
newf=$(echo "${a%.*}".$TYPE)
if -f "$newf" ]; then
echo "${NAME_}: skipping converting $a - $newf already exist" && continue
else
-f "$a" ] && mogrify -format $TYPE $a || continue
$verbose ]] && echo "${NAME_}: $a -> $newf"
$rm_input ]] && rm -f -- "$a"
fi
done
echo
exit 0
# end of script file
To make the script usable, open up a terminal session and type the following command:
chmod +x ~/bin/convert2
To use convert2, open another terminal session and enter convert2 with the following syntax:
Convert2 [type] -vhlr] <file> [file...]
If you request the help command (convert2 -h), here is what you get:
Convert2 1.00 - Convert image file from/to - bmp png jpg jpg pdf - format
Usage: Convert2 [type] -vhlr] <file> [file...]
Requires: standard GNU commands, ImageMagick
Type: bmp, png, jpg, gif or pdf: default Type is jpg
Options:
-r, remove the input file after conversion
-v, verbose
-h, usage and options (this help)
-l, see this script - Enter Q to Quit
convert2 presently supports the image types IMAGES_=“bmp png jpg gif pdf” as set by the value IMAGES_. You may add new ones to see if it is also supported. Don’t forget to modify the help information if you add something new. Don’t forget to let use know about it here.
Thank You,