Compress Pictures In Linux(Modified)!!!

I got the script to move the new compressed images into a new folder that would be located in your home folder.

As i explained before you need imagemagick installed on your system to run the script.
In ubuntu it can be installed by typing in the terminal sudo apt-get install imagemagick

Heres the script :
# 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
read -p 'Enter name of Folder where compressed images would be located (would be made in your home folder) : ' fname
mkdir ~/$fname
for pic
# New filename
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 !!!"
echo -n "$pic -> $out_name"
convert -quality 80 -resize 800x600 "$pic" "$out_name"
if [ ! -e "$out_name" ] ; then
echo " Error .. No output file!!!"
echo " ($(du -h "$out_name" | cut -f1))"
mv "$out_name" ./$fname/

I also didn’t explain the script properly in the previous post so i’ll that now.
Firstly the script should be copied from here and pasted in a text editor. Then save it as in your home folder(you can save it any where you wish but then how you call the scritp would change thats why its easier to save it in the home folder :)). Now open a terminal type:
animesh@animesh-laptop:~$ sudo chmod +x

after this do animesh@animesh-laptop:~$ ./ aaa.jpg
This would ask a for a folder where new image should be placed
Enter name of Folder where compressed images would be located (would be made in your home folder) :
Specify the name of a new folder where you wanna save the image.
The new compressed image would be saved in the folder you specified with the name aaa_new.jpg

You can also convert all pictures of a directory at once by
animesh@animesh-laptop:~$ ./ Desktop/linux09/*.JPG
This to would ask for a folder where you would like to save the new compressed images.

Now in the line convert -quality 80 -resize 800×600 “$pic” “$out_name” in script the value after -quality is the argument specifies the amount of JPEG/MIFF/PNG compression level, the lower the value(meaning 60 or 50) the higher is the compression(change it according to what you want). The -resize is used to resize an image, the argument following resize(i.e. 800×600) can be changed to what you want.
Leave a comment if you face any problems. :)