Categories
Debian

Bash Script Thumbnail

I wanted something to quickly take a bunch of images and make a gallery page. The linux binary convert and a Bash Script to create thumbnails did the trick:

I know this could be better, but it worked for what I needed it to do.


#!/bin/bash
FILES="$@"
echo "<html><head><title>generated thumbs</title></head><body>"
for i in $FILES
do
echo "<a href='$i'><img src='thumb.$i' alt='$i'/ ></a>"
/usr/bin/convert -thumbnail 150 ./$i ./thumb.$i
chown www-data.www-data $i
chown www-data.www-data thumb.$i
done
echo "</body></html>"

To run it, do something like this, but adjust your regex to create thumbnails out of whatever you want. The following code assumes you have some files that start with I (IMG_2012_07_15_1123.jpg) and some that start with thumb (thumb.IMG_2012_07_14_1234.jpg. I didn’t want to make thumbnails of my thumbnails so I said I*.jpg to only hit the big pictures:

sh thumbnails.sh I*.jpg > index.html

It results in something like this, except each thumbnail can be clicked for the original full size image:
Bash Script Thumbnail Gallery


The bash script thumbnail maker creats an output that has the gallery on one page. There is your Bash Script Thumbnail Maker!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.