Automating with Simple Shell Scripts – Part 2

Following on from the scripts published earlier, here’s an updated version that combines the two scripts previously mentioned. It now has some minimal error checking (checks for the presence of three variables) and converts the images to JPEG (if they weren’t already).

#!/bin/bash

if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then

echo "Usage: blog-resize <image prefix> <x scale> <path under images/>";
exit 0

else

for file in $1*
do
ls -x -l $file > tmp.list.1
a=`cut -d " " -f8 tmp.list.1`

echo $a > tmp.list.2
b=`cut -d "." -f1 tmp.list.2`

convert -scale 250 $file tn.$b.jpeg
convert -scale $2 $file $b.jpeg
done

rm tmp.list.1
rm tmp.list.2

closecounter=1

echo '<table align="center">' > imagelinks.html
echo '<tr><td colspan="3"><em>Click thumbnail for full-size image</em></td></tr>' >> imagelinks.html

echo '<tr>' >> imagelinks.html

for file in $1*.jpeg
do

echo '<td><a href="/images/'$3''$file'"><img src="/images/'$3'tn.'$file'" alt="'$file'" title="'$file'" /></a></td>' >> imagelinks.html
closecounter=$((closecounter+1))

if [ $closecounter -gt 3 ]
then
echo '</tr>' >> imagelinks.html
echo '<tr>' >> imagelinks.html

closecounter=1
fi

done

echo '</table>' >> imagelinks.html

fi

Advertisements
This entry was posted in Computing. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s