#!/bin/sh # # mkpg -- make a simple photo gallery # # This script uses a great little exif parser # named jname, available from http://www.sentex.net/~mwandel/jhead # # Canon MakerNote patch for jhead: # http://www.klake.eu.org/~jt/misc/jhead.diff # # File size conversion is done with ImageMagic's 'convert'. # # $Id: mkpg,v 3.7 2001/08/27 08:36:46 jt Exp $ # # HOWTO # # MAKE A GALLERY # # 1. Make a directory which contains all the pictures you want # include in your gallery. The script expects to see them in # JPEG format with Exif headers. # # $ mkdir gallery # # 2. Edit the file gallery/.mkpgrc (optional) - this file may # contain some variables used by the script, see below. # # 3. Edit the file gallery/.desc (optional). The format of this # file is as follows: # # file_name_1|This is a description for file_name_1|date_1 # file_name_2|This is a description for file_name_2|date_2 # ... # file_name_n|This is a description for file_name_n|date_n # # The date is useful only if your file doesn't contain the Exif # header. The description is optional - if it doesn't exist, the # script uses name of the file instead. # # 4. Make sure that the variables JHEAD CONVERT are set correctly # either in this file or in gallery/.mkpgrc # # 5. Run the command mkpg gallery # # ADD PICTURES # # You can more pictures to your gallery simply by copying the files # in your gallery directory. If you want to include description, edit # the file .desc. Then run the command "mkpg gallery". # # DELETE PICTURES # # 1. Delete Picture files in gallery directory, gallery/mids and # gallery/thumbs. # 2. Delete gallery/exif/file.exif (if exists) # 3. Remove the entry in dir/.desc (if exists) # 4. Run "mkpg path_to_gallery" # # CUSTOMIZE THE GALLERY # # Edit the variables in the file path_to_gallery/.mkpgrc or in this file and # Run "mkpg path_to_gallery". # VERSION=3.7 # # gallery/.mkpgrc can contain some variables, defaults are: # # Path to jhead program JHEAD=/home/jt/devel/html/pics/bin/jhead/jhead # Path to convert program CONVERT=/usr/X11R6/bin/convert # Background color for the HTML pages BGCOLOR=#ffffff # Middle size pictures are either small (512x384), medium (640x480) or # large (1024x768) MIDSIZE=small # The title of the gallery TITLE="Photo Gallery, mkpg version $VERSION" ####################################################################### # Check arguments ####################################################################### if [ -z "$1" ]; then echo "usage: $0 [dir] [title]" exit 1 fi if [ -n "$2" ]; then TITLE=$2 fi if [ -e $1/.desc ]; then DESC=jovain else DESC= echo "$0: Cannot find description file, using file names instead" fi if [ -e $1/.mkpgrc ]; then . $1/.mkpgrc fi if [ ! -e $1/thumbs ]; then mkdir $1/thumbs fi if [ ! -e $1/mids ]; then mkdir $1/mids fi if [ ! -e $1/exif ]; then mkdir $1/exif fi cd $1 ####################################################################### # Sort pictures ####################################################################### echo "$0: sorting" ( for PICS in *.jpg; do DATE=`$JHEAD $PICS | grep "^Date/Time" | awk -F": " '{print $2}' |\ sed 's/\(.*\):\(.*\):\(.*\) \(.*\):\(.*\):\(.*\)/\1\2\3\4\5\6/g'` if [ -z "$DATE" ]; then DATE=`date +%Y%m%d%H%M%S` fi echo $DATE:$PICS done ) | sort -n | awk -F":" '{print $2}' > .sorted DATE= if [ ! -s .sorted ]; then echo "$0: Found no .jpg files" exit 1 fi ####################################################################### # Write index ####################################################################### echo "$0: creating index.html" cat << EOF > index.html $TITLE

$TITLE

Master Index `date`

EOF ####################################################################### # Loop through picture files ####################################################################### for PICS in `cat .sorted`; do PICNAME=$PICS HTMLNAME=`echo $PICNAME | sed 's/\.jpg/\.html/g'` echo "$0: creating $HTMLNAME" # next and prev picture NUM=`grep -n "^$PICS" .sorted | awk -F":" '{print $1}'` LAST=`wc -l < .sorted` NEXT=$(($NUM+1)) PREV=$(($NUM-1)) if [ $PREV -eq 0 ]; then PREV= fi if [ $NEXT -gt $LAST ]; then NEXT= fi if [ -n "$PREV" -a -n "$NEXT" ]; then NEXT=`sed -n ''\$NEXT'p' .sorted | sed 's/\.jpg/\.html/g'` PREV=`sed -n ''\$PREV'p' .sorted | sed 's/\.jpg/\.html/g'` elif [ -n "$NEXT" ]; then NEXT=`sed -n ''\$NEXT'p' .sorted | sed 's/\.jpg/\.html/g'` PREV= else NEXT= PREV=`sed -n ''\$PREV'p' .sorted | sed 's/\.jpg/\.html/g'` fi # strip exif info if [ ! -e exif/$PICNAME.exif ]; then $JHEAD $PICS > exif/$PICNAME.exif fi # check the resolution RESO=`grep "^Resolution" exif/$PICNAME.exif | awk '{print $3}'` case $RESO in 480) CRESO=384x512 ;; 640) CRESO=512x384 ;; 768) CRESO=384x512 ;; 1024) CRESO=512x384 ;; 1200) CRESO=384x512 ;; 1600) CRESO=512x384 ;; 1392) CRESO=384x512 ;; 1852) CRESO=512x384 ;; 1536) CRESO=384x512 ;; 2048) CRESO=512x384 ;; *) CRESO=512x384 ;; esac case $MIDSIZE in small) ;; medium) case $CRESO in 384x512) CRESO=480x640 ;; 512x384) CRESO=640x480 ;; esac ;; large) case $CRESO in 384x512) CRESO=768x1024 ;; 512x384) CRESO=1024x768 ;; esac ;; *) ;; esac DATE=`grep "^Date/Time" exif/$PICNAME.exif | awk -F": " '{print $2}'` DATE=`echo $DATE |\ sed 's/\(.*\):\(.*\):\(.*\) \(.*\):\(.*\):\(.*\)/\1\/\2\/\3 \4:\5:\6/g'` # find description PDESC= if [ -n "$DESC" ]; then PDESC=`grep "^$PICNAME" .desc |\ awk -F"|" '{print $2}'` fi # find date - if not in exim, check .desc if [ -z "$DATE" ]; then DATE=`grep "^$PICNAME" .desc 2>/dev/null |\ awk -F"|" '{print $3}'` # no date found if [ -z "$DATE" ]; then DATE="unknown date" fi fi if [ -z "$PDESC" ]; then PDESC="$PICNAME ($DATE)" else PDESC="$PDESC ($DATE)" fi # Thumbnails - this is slow, do only once if [ ! -e mids/$PICNAME ]; then $CONVERT -geometry $CRESO $PICS mids/$PICNAME fi if [ ! -e thumbs/$PICNAME ]; then djpeg -scale 1/4 mids/$PICNAME | cjpeg -quality 30 > thumbs/$PICNAME fi # write index file cat << EOF >> index.html $PDESC EOF # write html file cat << EOF > mids/$HTMLNAME $PICNAME

$TITLE

EOF if [ -n "$NEXT" -a -n "$PREV" ]; then cat << EOF >> mids/$HTMLNAME [ Previous Picture ] [ Back to Index ] [ Next Picture ] EOF elif [ -n "$NEXT" ]; then cat << EOF >> mids/$HTMLNAME [ Back to Index ] [ Next Picture ] EOF else cat << EOF >> mids/$HTMLNAME [ Previous Picture ] [ Back to Index ] EOF fi cat << EOF >> mids/$HTMLNAME

$PDESC

$PDESC

[Full size]


Exif details

`cat exif/$PICNAME.exif`


Generated by mkpg-$VERSION, `date` EOF done ####################################################################### # End index ####################################################################### cat << EOF >> index.html


Generated by mkpg-$VERSION, `date` EOF