Compress Pictures In Linux!!!

I have made a script to compress a set of images so that they can be mailed as images taken form a digicam are normally of 10 or 15MB and to upload a set of images is a pain in the ***. :)

Firstly you need to install package Imagemagick
In ubuntu you can install by sudo apt-get install imagemagick

Now just copy the attached in an editor:
#!/bin/bash
# A script to resize images.
readonly OUT_FMT="_new.jpg"
if [ "$#" -eq 0 ] ; then
echo "A script to resize images "
echo "How to use : $(basename $0) add_of_image1 add_of_image2 ..."
exit 1
fi
for pic
do
# New filename
out_name="${pic%.*}$OUT_FMT"
if [ -e "$out_name" ] ; then
echo "Output file $out_name exists, Not resizing!!!"
elif [ "${pic#*$OUT_FMT}" == "" ] ; then
echo "$pic already resized!!!"
elif [ ! -r "$pic" ] ; then
echo "Error : could not access $pic !!!"
else
echo -n "$pic -> $out_name"
convert -quality 80 -resize 800x600 "$pic" "$out_name"
if [ ! -e "$out_name" ] ; then
echo " Error .. No output file!!!"
else
echo " ($(du -h "$out_name" | cut -f1))"
fi
fi
done

Now save it as resize.sh in your home folder.

Now in the terminal type
animesh@animesh-laptop:~$ sudo chmod +x resize.sh

after this do animesh@animesh-laptop:~$ ./resize.sh aaa.jpg
This would return a file aaa_new.jpg

You can also convert all pictures of a directory at once by
animesh@animesh-laptop:~$ ./resize.sh Desktop/linux09/*.JPG

The only problem with the script is that all the resized pictures would be in the same folder as original pictures. I am not able to move it in a new folder don’t know why. If you face any problem please leave a comment or if you know the solution to my problem please lemme know… :)
This post has being modified.