/home/projects/thumbnailer.sh :: page last updated 02010/01/31


thumbnailer.sh is another small bash script, here designed to automate the process of resizing, renaming, and uploading images to my site. It can, of course, be used to upload files to any computer. It requires imagemagick (for image resizing) scp (for uploading) and any bash compatible shell. It can be downloaded here, or copied by hand from the complete source, which follows.


#!/bin/sh
#
# Thumbnailer, HTML generator, uploader.
#
# Takes an image file, renames it to whatever you tell it to, produces two resized copies (500 and 1200 pixels wide) and uploads them to a remote site using scp.
# The second argument doesn't take an extension! Don't add one!

FILE=$1
NAME=$2

if [ -z "$FILE" ]
   then
   echo "[!] This script needs an image file as an input."
   exit 1
fi

if [ ! -f "$FILE" ]
   then
   echo "[!] File does not exist."
   exit 1
fi

if [ -z "$NAME" ]
    then
    echo "[!] Please specify a name."
    exit 1
fi

EXTENSION=${FILE##*.}

echo '<a href="http://bbot.org/blog-images/'$NAME.$EXTENSION'"><img src="http://bbot.org/blog-images/'$NAME'-thumb.'$EXTENSION'"></a>'

convert -verbose -quality 90 -geometry 1200 "$FILE" "$NAME.$EXTENSION"

convert -verbose -quality 80 -geometry 500 "$FILE" "$NAME"-thumb".$EXTENSION"

#Don't forget to put in your remote host, or else it'll try to upload it to bbot.org

scp $NAME.$EXTENSION $NAME"-thumb".$EXTENSION bbot@bbot.org:srv/blog-images/