Resize all the images in directory.

Geotagger "Solmeta N2 Kompass" for N...
Image via Wikipedia

When I take a photo with my DSLR Nikon D5000, the size of the image comes to around 5MB and I know that with my point and shoot camera also it does not come to any lesser than 3MB. Definitely this is quite good to keep the images in the same size for use but when it comes to on-line sharing I don’t think this is the size that is required. I guess mosr of the time 1024×768 is sufficient. Even if you are sending the images in email, you cannot afford to send a lot of images of this size even with a gmail account.

So, what do you do? Again you cannot open gimp or any such program to modify couple of photos and spend couple of hours in modifying the files before sharing or sending it in email. So, if you are on linux (which you are, if you are reading this blog entry), then here’s a simple bash script that you can use to resize all your images.

1
2
3
4
5
6
7
8
9
10
11
12
13
size="<a class="zem_slink" title="Display resolution" rel="wikipedia" href="http://en.wikipedia.org/wiki/Display_resolution">640x480</a>"

prefix="img-"

for i in *;
do
t=`file $i`
if [[ "$t" =~ 'image' ]]
then
convert -resize $size $i $prefix$i
echo "$i resized";
fi
done

Note: You will not get the exact size of image as specified in the size option. For example if you specify 640×640 still you would get 640×480 depending on your photos aspect ratio. Also, you can specify the size in percentage like “50%” 🙂

Enhanced by Zemanta