Bash Thumbnailer Script with Imagemagick

A while ago, I was working on creating a script to create thumbnails of all the pictures I had taken so I could put them up on my personal site for family/friends to view. It started out as a very basic script but as I developed my website, I found new ways to display the photos. Namely using css for the image to come up double sized by mousing over on the picture. Well this created quite a challenge to put all the code for my pictures in the HTML. So I went a step further and adjusted the script to create the php necessary for the galleries. The way I create all my pages is to use a standard header and footer file and include them into my individual pages. So I then changed the script so it created a full blown page ready to be used. The script is below. You may have to modify it slightly for your own needs, but it should work fine. The main requirement is the imagemagick software. In Slackware it is included with the default install. With your own distro you may need to add it yourself.

[code=’bash’]
#!/bin/bash

echo “Resizing Pictures and Creating PHP”
mkdir thumbs previews view
cp ../rhine-river/view.php .
cp ../rhine-river/download.php .

totalcount=0
currentcount=0

if [ $1 = y ]
then
name=$2
picnum=0
for i in *.jpg *.JPG; do

picnum=$(($picnum + 1))

pic=`echo $i | awk -F . ‘{print $1}’`
rename=”${name}-`printf “%03d” $picnum`.jpg”
mv “$i” $rename

done
fi

for i in *.jpg; do

totalcount=$(($totalcount + 1))

done

echo “There are $totalcount pictures to convert.”

# Create the header
echo \<\?php > index.php
echo \$pagetitle \= \”Insert Title Here\”\; >> index.php
echo include_once\(\”../../includes/header.php\”\)\; >> index.php
echo ?\> >> index.php
echo \Page Description Here\ >> index.php
echo \

1 thought on “Bash Thumbnailer Script with Imagemagick

Leave a Reply

Your email address will not be published. Required fields are marked *