Call: (480) 382-8464

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 *

Main Offers/Services

Hosting and website related services offered by Digital Crunch:



Managed VPS Hosting

Server Updates, Module/Software Installs, Firewall, Security, Hosting Management, Wordpress - let us manage it for you

Hosted Email

Setup and Maintain Business Class, Secure Email Hosting including spam protection and 25GB of storage space

Linux Consulting

Server Updates, Module/Software Installs, Firewall, Security, Hosting, Wordpress and Apps, anything related to Linux

Email Marketing Services

We broadcast your content to your list, capture leads for you, follow up on schedules, make more sales for you

Website Maintenance

Content updates, menu changes, graphics changes, adding content, getting links, building traffic, building sales funnels

Hosting Tutorials

Tutorials we've written for other customers that like to get their hands dirty and learn about hosting