# Take the .jpeg images in a directory and convert them # into big and small images in subdirectories big and small. # Then create a basic web page which incorporates the # small images and links them to the big ones. # $Id: Makefile,v 1.31 2008/03/21 00:13:15 grog Exp $ # Rules in this Makefile define a number of shell/make variables # that get substituted into the pages. They are: # DIR: name of this directory relative to ~/public_html # BASEDIR: base name of this directory. # DATE: Date in printable form. # DIARY: Name of diary entry encoded for date. # IMAGE: Name of image file. # BASE: Name of image file without extension. # DEST: Name of the index page in public_html. # The web page bits and things are here TOOLS ?= ~grog/Photos HTML_TIDY ?= ${TOOLS}/.tidyconfig # reduction ratios for small and tiny WIDTHsmall ?= 600 WIDTHtiny ?= 300 SHELL = bash HOMEDIR= `cd; pwd` # Web page name PAGE?= index.html TINYPAGE?= thumbnails.html PDIR?= public_html PUBPHOTOS?= ~/${PDIR}/photos HOUSEPHOTOS?= /home/grog/public_html/kleins-road # Name of index file. This doesn't have to exist. # PHOTOINDEX?= ../../photos/photos.php all: webpage # XXX delete me Makefile: bash -c "ln -s ${TOOLS}/Makefile ." && true # Make all the stuff in the web directories. Used to be: # webpage: big small tiny index.html newphotos.html webpage: big thumbnails.html: big small tiny RCS echo +++ $@ if [ -f ${TINYPAGE} ]; then \ mv -f ${TINYPAGE} ${TINYPAGE}~; \ fi if [ -f RCS/${TINYPAGE},v ]; then \ rcs -l ${TINYPAGE}; \ fi XXDIR=`pwd`; \ DIR=Photos/`basename $$XXDIR`; \ BASEDIR=`basename $$DIR`; \ DATE=`${TOOLS}/dateconv -d $$BASEDIR`; \ DIARY=`${TOOLS}/dateconv $$BASEDIR`; \ if [ -f ../thumbnail-0.html ]; then \ THUMB0=../thumbnail-0.html; \ else \ THUMB0=${TOOLS}/thumbnail-0.html; \ fi; \ sed < $$THUMB0 "s:BASEDIR:$$BASEDIR:g; s:DIRECTORY:$$DIR:; s:DATE:$$DATE:;s:DIARY:$$DIARY:" > ${TINYPAGE}; \ for j in `ls -rt big`; do \ i=`basename $$j`; \ BASE=`${TOOLS}/basefilename $$i`; \ SIZE=`du -k big/$$i | awk '{print $$1}'`; \ IMAGESIZE=`identify tiny/$$i | sed 's:.*JPEG ::; s:.*GIF ::; s: .*::'`; \ HORIZPIXELS=`echo $$IMAGESIZE | sed 's:x.*::'`; \ VERTPIXELS=`echo $$IMAGESIZE | sed 's:.*x::'`; \ grep -v '^#' < ${TOOLS}/thumbtemplate | \ sed "s:IMAGE:$$i:g; s:BASEDIR:$$BASEDIR:g; s:DIR:$$DIR:g; s:SIZE:$$SIZE:g; s:BASE:$$BASE:g; s:HORIZPIXELS:$$HORIZPIXELS:g; s:VERTPIXELS:$$VERTPIXELS:g" \ >> ${TINYPAGE}; \ done; \ if [ -f ../thumbnail-n.html ]; then \ THUMBN=../thumbnail-n.html; \ else \ THUMBN=${TOOLS}/thumbnail-n.html; \ fi; \ cat $$THUMBN >>${TINYPAGE}; \ tidy -m -asxhtml $@; \ PDIR=`cd; pwd`/public_html; \ ci -m"Created by 'make webpage'" -t-"Basic web page for photos in this directory" -u ${TINYPAGE}; \ if [ $$PDIR != `pwd` ]; then \ DEST=~/public_html/Thumbnails-`basename $$XXDIR`.html; \ echo; echo Copying $$DIR to $$PDIR; echo; \ echo cp -p ${TINYPAGE} $${DEST}; \ rm -f $${DEST}; \ cp -p ${TINYPAGE} $${DEST}; \ rcs -l $${DEST} && true; \ ci -u -t-\\"Thumbnail photos from $${DATE}\\" -m"Automatic checkin" $${DEST}; \ chmod +w $${DEST}; \ else \ echo; echo No need to link `pwd` to $$PDIR; echo; \ fi # Create a set of linked web pages. # Don't call this target directly; you'll be in the wrong directory .linkedimages: XXDIR=`pwd`; \ DIR=Photos/`basename $$XXDIR`; \ BASEDIR=`basename $$DIR`; \ DIARY=`${TOOLS}/dateconv $$BASEDIR`; \ DEST=Thumbnails-`basename $$XXDIR`.html; \ sh ${TOOLS}/makelinkedimages ../../$$DIARY ${TOOLS} ../../$$DEST `ls -rt big/*${IMAGETYPE}` touch .linkedimages # Make the index page with the "small" photos (renamed to Photos-DATE.html) # Old version, deletion candidate XXX oldindex.html: thumbnails.html .linkedimages echo +++ $@ if [ -f ${PAGE} ]; then \ mv -f ${PAGE} ${PAGE}~; \ fi if [ -f RCS/${PAGE},v ]; then \ rcs -l ${PAGE}; \ fi XXDIR=`pwd`; \ DIR=Photos/`basename $$XXDIR`; \ BASEDIR=`basename $$DIR`; \ DATE=`${TOOLS}/dateconv -d $$BASEDIR`; \ DIARY=`${TOOLS}/dateconv $$BASEDIR`; \ if [ -f ../index-0.html ]; then \ sed < ../index-0.html "s:BASEDIR:$$BASEDIR:g; s:DIRECTORY:$$DIR:; s:DATE:$$DATE:;s:DIARY:$$DIARY:" > ${PAGE}; \ else \ sed < ${TOOLS}/index-0.html "s:BASEDIR:$$BASEDIR:g; s:DIRECTORY:$$DIR:; s:DATE:$$DATE:" > ${PAGE}; \ fi; \ for j in `ls -rt big`; do \ i=`basename $$j`; \ BASE=`${TOOLS}/basefilename $$i`; \ SIZE=`du -k big/$$i | awk '{print $$1}'`; \ IMAGESIZE=`identify small/$$i | sed 's:.*JPEG ::; s:.*GIF ::; s: .*::'`; \ HORIZPIXELS=`echo $$IMAGESIZE | sed 's:x.*::'`; \ VERTPIXELS=`echo $$IMAGESIZE | sed 's:.*x::'`; \ grep -v '^#' < ${TOOLS}/imgtemplate | \ sed "s:IMAGE:$$i:;s:DIR:$$DIR:; s:SIZE:$$SIZE:; s:BASE:$$BASE:g; s:HORIZPIXELS:$$HORIZPIXELS:g; s:VERTPIXELS:$$VERTPIXELS:g" >> ${PAGE}; \ ${TOOLS}/findexif big/$$i $$DIR/$$BASE ${PAGE}; \ done; \ if [ -f ../index-n.html ]; then \ INDEXN=../index-n.html; \ else \ INDEXN=${TOOLS}/index-n.html; \ fi; \ sed < $$INDEXN "s:BASEDIR:$$BASEDIR:g; s:DIRECTORY:$$DIR:; s:DATE:$$DATE:;s:DIARY:$$DIARY:" >> ${PAGE}; \ PDIR=`cd; pwd`/public_html; \ tidy -m -asxhtml $@; \ emacs -batch -l ~/.emacs $@ -f retidy-html -f save-buffer -f kill-emacs; \ ci -m"Created by 'make webpage'" -t-"Basic web page for photos in this directory" -u ${PAGE}; \ PDIR=`cd; pwd`/public_html; \ if [ $$PDIR != `pwd` ]; then \ DEST=~/public_html/Photos-`basename $$XXDIR`.html; \ echo cp -p ${PAGE} $${DEST}; \ rm -f $${DEST}; \ cp -p ${PAGE} $${DEST}; \ rcs -l $${DEST} && true; \ ci -u -t-\\"Photo index page from $${DATE}\\" -m"Automatic checkin" $${DEST}; \ chmod +w $${DEST}; \ fi # All that's left of index.html: # exif processing # create photolist.php # # We're asserting here that identify always prints out the resolution # in $3 in the form x. auxfiles: echo +++ $@ MYDIR=`pwd`; \ WEBDIR=~/public_html/Photos/`basename $$MYDIR`; \ XXDIR=`pwd`; \ DIR=Photos/`basename $$XXDIR`; \ BASEDIR=`basename $$DIR`; \ DATE=`${TOOLS}/dateconv -d $$BASEDIR`; \ DIARY=`${TOOLS}/dateconv $$BASEDIR`; \ cd $$WEBDIR; \ rm -f photolist.php; \ for j in `ls -rt big`; do \ BASE=`${TOOLS}/basefilename $$j`; \ TINYKS=`du -k tiny/$$j | awk '{print $$1}'`; \ TINYSIZE=`identify tiny/$$j | awk '{print $$3}'`; \ TINYHORIZ=`echo $$TINYSIZE | sed 's:x.*::'`; \ TINYVERT=`echo $$TINYSIZE | sed 's:.*x::'`; \ SMALLKS=`du -k small/$$j | awk '{print $$1}'`; \ SMALLSIZE=`identify small/$$j | awk '{print $$3}'`; \ SMALLHORIZ=`echo $$SMALLSIZE | sed 's:x.*::'`; \ SMALLVERT=`echo $$SMALLSIZE | sed 's:.*x::'`; \ BIGKS=`du -k big/$$j | awk '{print $$1}'`; \ BIGSIZE=`identify big/$$j | awk '{print $$3}'`; \ BIGHORIZ=`echo $$BIGSIZE | sed 's:x.*::'`; \ BIGVERT=`echo $$BIGSIZE | sed 's:.*x::'`; \ echo >> photolist.php $$j $$TINYHORIZ $$TINYVERT $$TINYKS \ $$SMALLHORIZ $$SMALLVERT $$SMALLKS \ $$BIGHORIZ $$BIGVERT $$BIGKS; \ exif big/$$j > $$BASE.exif || true; \ LINES=`cat $$BASE.exif | wc -l`; \ if [ $$LINES -lt 6 ]; then \ rm -f $$BASE.exif; \ fi; \ done # Add the description to the dirlist file. adddescription: description @echo +++ $@ -DIRLIST=~/public_html/photos/dirlist; \ BASEDIR=`basename \`pwd\``; \ grep $$BASEDIR $$DIRLIST >/dev/null; \ if [ $$? -eq 0 ]; then \ echo Entry for $$BASEDIR already exists in $$DIRLIST; \ else \ co -l $$DIRLIST; \ echo -n "$$BASEDIR " >> $$DIRLIST; \ cat ~/Photos/$$BASEDIR/description >> $$DIRLIST; \ ci -u -m"Automatic checkin" $$DIRLIST; \ fi # Description file for index. I make an exception to my "no # interactive Makefiles" here, because it's so much work to fix if the # thing doesn't exist. description: -DIR=`pwd | sed 's:.*public_html/::'`; \ BASEDIR=`basename $$DIR`; \ DATE=`${TOOLS}/dateconv -d $$BASEDIR`; \ OLDDESC=`grep $$BASEDIR ${PUBPHOTOS}/dirlist | sed 's:[0-9]* *::'`; \ if [ "$$OLDDESC" != "" ]; then \ echo No description file ; \ echo Using old description: ; \ echo ; \ echo $$OLDDESC ; \ echo $$OLDDESC > $@ ; \ else \ echo $$DATE > $@ ; \ fi # This is rest of the old code for description, which may have some tricks that I have forgotten. # XXX deletion candidate newphotos.html: -DIR=`pwd | sed 's:.*public_html/::'`; \ BASEDIR=`basename $$DIR`; \ DIRLIST=~/public_html/photos/dirlist; \ DATE=`${TOOLS}/dateconv -d $$BASEDIR`; \ DIARY=`${TOOLS}/dateconv $$BASEDIR`; \ if [ $$BASEDIR -lt 20070000 ]; then \ echo ; \ echo "*** $$BASEDIR is too old for the current index file, so, and I won't update it."; \ echo "*** Put this in your index file and smoke it:"; \ echo ; \ echo \\\Photos taken round $$DATE\\\\Thumbnails\\\\diary entry\\\ > $@; \ cat $@; \ echo ; \ else \ if [ "${PHOTOINDEX}" = "" ]; then exit 0; fi; \ if [ ! -f "${PHOTOINDEX}" ]; then exit 0; fi; \ grep '' ${PHOTOINDEX} >/dev/null; \ if [ $$? -ne 0 ]; then \ echo ; \ echo "*** ${PHOTOINDEX} doesn't look like a photo index, and I won't update it."; \ echo "*** Put this in your index file and smoke it:"; \ echo ; \ echo \\\Photos taken round $$DATE\\\\Thumbnails\\\\diary entry\\\ > $@; \ cat $@; \ rm $@; \ exit 0; \ else \ grep Photos-$$BASEDIR.html ${PHOTOINDEX} \ && echo && echo "Entry for $$DATE already exists in `pwd`/${PHOTOINDEX}" && exit 0; \ echo ; \ echo ; \ grep HAVEDIARY ${PHOTOINDEX}; \ if [ $$? -ne 0 ]; then \ sed < ${PHOTOINDEX} > $@ \ "s::Photos taken round $$DATEThumbnails:"; \ else \ sed < ${PHOTOINDEX} > $@ \ "s::Photos taken round $$DATEThumbnailsdiary entry:"; \ fi; \ tidy -m -asxhtml $@; \ emacs -batch -l ~/.emacs $@ -f retidy-html -f save-buffer -f kill-emacs; \ co -l ${PHOTOINDEX}; \ cp -p $@ ${PHOTOINDEX}; \ ci -m"Autocheckin" -u ${PHOTOINDEX}; \ rm -f $@~; \ fi; \ fi housephotos: co -l ${HOUSEPHOTOS}/photo-dates.php mv ${HOUSEPHOTOS}/photo-dates.php /var/tmp/housephotos.$$$$; \ CWD=`pwd`; \ DATE=`basename $$CWD`; \ echo Photos/$$DATE >> /var/tmp/housephotos.$$$$; \ sort /var/tmp/housephotos.$$$$ | uniq > ${HOUSEPHOTOS}/photo-dates.php; \ co -l ${HOUSEPHOTOS}/exterior.php; \ sed < ${HOUSEPHOTOS}/exterior.php > /var/tmp/housephotos.$$$$ \ "s:date = \"........:date = \"$$DATE:"; \ mv /var/tmp/housephotos.$$$$ ${HOUSEPHOTOS}/exterior.php -ci -u -m"Automatic update by 'make housephotos'" ${HOUSEPHOTOS}/photo-dates.php \ ${HOUSEPHOTOS}/exterior.php awk -f ${TOOLS}/housephotos.awk ${HOUSEPHOTOS}/photo-notes | sh extend: ${TOOLS}/extend *[0-9.] RCS big: .FORCE echo +++ $@ MYDIR=`pwd`; \ WEBDIR=~/public_html/Photos/`basename $$MYDIR`; \ mkdir -p $$WEBDIR/$@ tiny small: .FORCE echo +++ $@ MYDIR=`pwd`; \ WEBDIR=~/public_html/Photos/`basename $$MYDIR`; \ mkdir -p $$WEBDIR/$@; \ cd $$WEBDIR/big; for i in *; do \ if [ ! -e ../$@/$$i ]; then \ IMAGESIZE=`identify $$i | sed 's:.*JPEG ::; s:.*GIF ::; s: .*::'`; \ HORIZPIXELS=`echo $$IMAGESIZE | sed 's:x.*::'`; \ VERTPIXELS=`echo $$IMAGESIZE | sed 's:.*x::'`; \ if [ "$$VERTPIXELS" -gt "$$HORIZPIXELS" ]; then \ convert -geometry x${WIDTH$@} $$i ../$@/$$i; \ else \ convert -geometry ${WIDTH$@} $$i ../$@/$$i; \ fi; \ fi; \ done clean: rm -f *~ clobber: if [ -d big ]; then \ rm -rf big small tiny RCS; \ fi # Link all .jpeg, .png and .gif files in the source directory to the # 'big' subdirectory of the web directory. We're in the source # directory when this runs. copy: big MYDIR=`pwd`; \ WEBDIR=~/public_html/Photos/`basename $$MYDIR`; \ for i in `ls description heading title *.desc 2>/dev/null`; do \ rm -f $${WEBDIR}/$$i; \ ln $$i $${WEBDIR}; \ done; \ for i in `ls *.gif *.jpeg *.png 2>/dev/null`; do \ if [ ! -e $${WEBDIR}/big/$$i ]; then \ ln $$i $${WEBDIR}/big; \ fi; \ done # XXX deletion candidate link: big echo XXX target $@ what's this?' exit 1 ln -s ~/Photos/`basename \`pwd\``/*${IMAGETYPE} big # This target is to be called in the archive directory under ~/Photos. # It creates a directory ~/public_html/Photos/ and populates it. web: extend MYDIR=`pwd`; \ WEBDIR=~/public_html/Photos/`basename $$MYDIR`; \ mkdir -p $$WEBDIR; \ make -f ~/Photos/Makefile copy small tiny adddescription auxfiles clean # Clean away the stuff built by the 'web' target cleanweb: .FORCE MYDIR=`pwd`; \ rm -rf ~/public_html/Photos/`basename $$MYDIR` .FORCE: test: echo ${HOMEDIR} echo ${PDIR}