#!/bin/bash # # Syntax: mk_thumbnails [-h] [-w width] file [...] # # Purpose: Creates thumbnails for the given files using the convert # command. The output file names are of the form TN_file. # The default value for width is 100. # In fact, instead of the width you can also also specify a # geometry (like scale%, xheight, widthxheight etc.) as argument # of the -w flag. # The -h flag shows the help info for this command. # Created: Jan 1, 2011 by Bart De Schutter # Last revised: # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: images # # Define default options # geometry="100" # # Process options # while getopts :hw: option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; w) geometry=$OPTARG;; :) echo >&2 echo >&2 "Option -$OPTARG requires an argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 echo >&2 exit 1;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done shift $(($OPTIND-1)) # # Check whether there is any output argument present. # if [ $# -eq 0 ] then echo >&2 echo >&2 "ERROR: ${0##*/} requires at least 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi # # Process files. # for fil in "$@" do convert -thumbnail "$geometry" "$fil" "TN_$fil" echo "$fil" processed done