#!/bin/bash ## ## Generate Thumbnails and an index.html in a galleryesque fashion ## Nicholas DeClario ## February 2011 ## $Id: tn,v 1.3 2011/02/16 14:17:47 nick Exp $ ## ## I'm not using any additional methods to pull in command line options ## at this time so it works as follows. ## ## tn html_file thumb_size columns_in_page filename_on add_directory_links ## ## If you want to specify the columns you must also specify the html_file ## and thumb_size first, for example: ## ## tn index.html 64 3 ## ## The defaults, if nothing is specifed is 'index.html' for the html file, ## 64x64 for the thumbnail size, 6 images row and filenames under the ## images disabled. ## HTML=${1:-index.html} TN_SIZE=${2:-64} MAX_COL=${3:-6} FNAMES=${4:-0} DIRECTORIES=${5:-0} TN_DIR=thumbs TITLE="`hostname`:`pwd`" FILE_TYPES="jpg png jpeg gif" [ -d $TN_DIR ] || mkdir $TN_DIR cat <$HTML $TITLE

$TITLE

EOF CNT=0 for i in $FILE_TYPES; do for n in `find -maxdepth 1 -type f -iname \*.$i`; do TN=`basename $n .$i`-tn.$i; convert -resize $TN_SIZE $n $TN_DIR/$TN [ $CNT -ge $MAX_COL ] && \ { echo -e "\n" >>$HTML CNT=0 } [ $FNAMES -eq 0 ] || \ IMAGE_NAME="
`basename $n`" cat <>$HTML EOF CNT=$(( CNT + 1 )) done done ## ## Link directories if enabled ## [ $DIRECTORIES -eq 0 ] || \ { echo -e "\n\n" } >> $HTML cat <>$HTML
$n  $IMAGE_NAME
\n\t
    " for dir in `find . -maxdepth 1 -type d`; do dir=`basename $dir` [ "$dir" != "$TN_DIR" ] && [ "$dir" != "." ] && \ echo -e "\t\t
  • $dir
  • " done echo -e "\t
\n

Generated on `date`.
Generated with command '$0 $*' by `whoami`.

Valid XHTML 1.0 Transitional

EOF