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 :
#!/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
read -p 'Enter name of Folder where compressed images would be located (would be made in your home folder) : ' fname
mkdir ~/$fname
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
mv "$out_name" ./$fname/
done

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 resize.sh 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 resize.sh

after this do animesh@animesh-laptop:~$ ./resize.sh 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:~$ ./resize.sh 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. :)