Linux - 7 - preparing images for the web
i used to use a program called easy thumbnails under Windows to produce thumbnails and downsize photos for my website. i made thumbnails have a maximum height of 100 pixels, and reduced photos to a maximum height of 480. This helps to keep file sizes down to improved site interactivity. Also most people don't have screens larger enought to show all of a photo at once, so the extra resolution is wasted.
i'm hoping to produce a script that does the same as easy thumbnails, but just under linux, with less hassel.
Software required
It would seem that ImageMagick would be the de facto for linux image manipulation. i downloaded it, unzipped, and installed without negative incident. i later found it was already on my distribution. Dammit.
The script
The following takes one parameter which is the directory to convert. All the images are copied into a newly created directory suffixed with webprep, any JPG extensions are changed to jpg, and Thumbs.db files are deleted. Thumbnails of height 100 are created prefixed with th_, and all the images are scaled down to have a height of 480.
#!/bin/bash
#make new directory, copy files into it
rm -rf $1.webprep
mkdir $1.webprep
cp -f $1/* $1.webprep
cd $1.webprep
#rename as jpg extensions rather than JPG
for i in `find . -regex '.*\.JPG'`
{
mv $i `echo $i | sed -e 's/\.JPG/.jpg/'`
}
#make thumbnails
for i in `find . -regex '.*\.jpg'`
{
thfilename=th_`basename $i`;
convert -geometry x100 $i $thfilename;
mogrify -geometry x480 $i
echo $i;
}
Conclusions
All i need to do now is to type webprep to prepare a directory of images for the web. This is so much easier than under windows. It still takes a while though, working through the images at the rate of about one every couple of seconds.