#!/bin/bash
## scalepix -- creates thumbnail & annotated-web-scaled version for each of a given set of images -- by Eugene Reimer, 2001-Oct;
## PREREQ: convert -- from Imagemagick
## PREREQ: pnmfile pnmscale -- from Netpbm
## PREREQ: bc annotatepix datecvt -- from http://ereimer.net/programs/general-purpose-scripts.htm
##
## USAGE EXAMPLES:
## scalepix 02feb*jpg ##produce 160px Thumbnails for selected JPEG files
## scalepix -p450 02feb*jpg ##also produce 450px (Photo) versions annotated with Photographer-name and Date
## scalepix -p450 -t0 02feb*jpg ##produce only 450px (Photo) versions annotated with Photographer-name and Date
## SLIDESHOW EXAMPLES:
## scalepix -t0 -s1024x768 -q90 -a16 -b16 CS-* ##for the ChurchillTrip-slideshow
## scalepix -t0 -s1024x768 -q90 -a16 -b16 -r16 -c white SS* ##for the SS-OrchidsThruYear-PROJECTOR-slideshow 05apr
## scalepix -t0 -s1024x768 -q90 -a24 -b16 -r24 -PB SS* ##for the SS-OrchidsThruYear-VCR-slideshow
## scalepix -t0 -s1024x768 -q90 -a16 -b16 -PA CS-* ##for the OperaShow Churchill-slideshow 05june6
## scalepix -t0 -s1600x1200 -q90 -a25 -b25 -PA BD[0-9]* ##for the ooImpress->PPT BeautyInDiversity-slideshow 06may/june
##
## IMAGE-NAMING CONVENTIONS:
## this script accepts and produces image-filenames that look like:
## Anything_Location_Date_PhotographerAlterationlettersSize.jpg
## where:
## Anything contains anything except underscore;
## Date is in YYYYMMDD style;
## Photographer can be the full name with a tilde where space is wanted, eg: Heather~Reeves, or one of the 2-letter (lowercase) abbreviations defined below;
## Alterationletters is any string of uppercase-letters, digits, hyphens, but ending in uppercase-letter;
## Size typically not present on input image, but is supplied for the output image(s) subject to --NOSZ option;
## is in units where a size of 720 means having the same area (total number of pixels) as a 4:3 photo that's 720-pixels in the bigger dimension;
## note that the -pSIZE and -tSIZE options specify size in these units;
## note: not all filename components are required, in fact none are; however annotation is only done if _Photographer is present;
## when fewer underscores are present, the ones that are present are taken to be the rightmost ones;
## note: input images may be of any image-type (gif, png, tif, etc, as well as jpg); output images are jpg by default but subject to -oTYPE option;
##
## Copyright © 2001,2009 Eugene Reimer; can be used, modified, copied, and distributed or sold under the terms of either the LGPL or the GPL (your choice);
## see http://www.gnu.org/licenses for the details of these terms.
DATE=$(date +%y%b%d)
Thumbs=tmpThumbs.htm
Photos=tmpPhotos.htm
Pnames=tmpPnames.txt
[ -e $Thumbs ] || echo "
Thumbs $DATE" >$Thumbs
[ -e $Photos ] || echo "Photos $DATE$DATE
" >$Photos
##==Defaults for the Cmdline-Options, with explanation:
##Hsize=0 ## -h max size of an "original", default is UNLIMITED; 2009-11: YANKED this obsolete option
Psize=0 ## -p size of photo versions to produce, default is NO "Photo" versions produced
Pwd=; Pht=; ## -s maxwidth maxheight - an alternate way to specify size of photo versions to produce
Tsize=160 ## -t size for Thumbnail versions; default is to produce thumbnails (specify -t 0 to suppress)
Asize=-1 ## -a text-size for annotation; was 10; see below for new default of 8 + Psize/150
Aborder=-1 ## -b text-border (distance from Bottom) for annotation; was 7; now one-half of Asize -- eg: for powerpoint-slideshow -b 14
Acolor="" ## -c text-color for annotation; was:Acolor=white, prior to adding ink-color-picking logic
##ont=microsoft-Verdana ## -f text-font for annotation; old-method; was:adobe-helvetica until 04jan31, again 05nov thru 06apr (lacked truetype in FC4)
Afont=verdana-bold ## -f text-font for annotation; now a GS-Fontname 2008-11-22; show-fonts-gs shows the choices; bold nice if low-contrast, see annotatepix;
Amargin=-1 ## -m text-margin (distance from Left) for annotation; was:50; 03sep:25; 03nov:20; 06jun:Asize*2; 08aug:Asize*1.3;
AsizeR=0 ## -r text-size for "Remark" annotation, default is NO "Remark" annotation; BEWARE: -r not usable w/o customization;
##Hqual=95 ## -Q.1 Huge-quality, default 95, for Huge Resizing controlled by -h; was 1st-opnd of -Q but now OBSOLETE
Pqual=85 ## -q Photo-quality, default 85, for Photo version -p/-s default was:75 until 05apr25; was 2nd-opnd of -Q
Tqual=85 ## -Q Thumb-quality, default 85, for Tiny/Thumbnail version -t; 2009-03: changed 75-->85; was 3rd-opnd of -Q now the only -Q-opnd
Format=jpg ## -o output file-format; default is JPEG
PadB="" ## -PB pad to the -s size, before annotation => annotation can be on top of the padding
PadA="" ## -PA pad to the -s size, after annotation => annotation is on the picture only
PadColor=black ## -PWB and -PWA set this to white
NOSZ=0 ## -NOSZ avoid adding sz to photo-filename, default is to add sz; new 06jun14 -- DANGEROUS if scaling into same dir
MAXR=9999 ## -M nbr maximum scaling ratio, eg: -M 1.5 to limit scaling-ratio to 1.5; new 07mar
FULLDATE=0 ## -FULLDATE to get annotation-date as YYYY-MM-DD (default is YYYY); new 2008-02-28
CPYRIGHT=0 ## -CPYRIGHT for annotation-text to include copyright-symbol; new 2008-02-28
CAPANNO= ## -CAPANNO for Caption+Location in annotation-text; new 2009-10 (now -CP is min-abbrev for -CPYRIGHT)
DISTORT= ## -DISTORT used together with -s for result exactly that size; new 2009-10
PRF= ## -PREFIX string prefixed to resulting photo/thumb-filenames; new 2009-10
USAGE="Usage: scalepix [-p PHOTOSIZE / -s MAXWIDTHxMAXHEIGHT] [-t THUMBNAILSIZE] IMAGEFILENAME..."
##==Parsing cmdline options with getopt:
if [[ $1 == -\? ]];then echo "$USAGE"; exit 0;fi ##because getopt doesn't support question-mark as a short-option
TEMP=$(getopt -a -nscalepix -o hp:s:t:a:b:c:f:m:r:o:q:Q:S: --long help,PA,PB,PWA,PWB,NOSZ,MAXR:,FULLDATE,CPYRIGHT,CAPANNO,DISTORT,PRF: -- "$@")
if [ $? != 0 ];then echo "$USAGE"; exit 2;fi
eval set -- "$TEMP"
while [ $# -gt 0 ] && [[ $1 == -* ]];do ##parse options loop; same as before using getopt, except for double-dash on long-options
case "$1" in
## -h) Hsize=$2; shift 2;; ##2009-11: obsolete
-p) Psize=$2; Pht=0; shift 2;; ##AREA: Pwd=Psize;Pht=Psize --> Pht=0
-s) Pwd=${2%x*};Pht=${2#*x}; ((Psize=Pht*4/3)); shift 2;; ##2009-11: 1-opnd; was Pwd=$2;Pht=$3...shift 3; was Psize=Pwd (Psize needed for default Asize)
-t) Tsize=$2; shift 2;;
-a) Asize=$2; shift 2;;
-b) Aborder=$2; shift 2;;
-c) Acolor=$2; shift 2;;
-f) Afont=$2; shift 2;;
-m) Amargin=$2; shift 2;;
-r) AsizeR=$2; shift 2;; ##2010-05: beware: -r option not usable w/o some customization...
-o) Format=$2; shift 2;;
-q) Pqual=$2;[ $Pqual -lt $Tqual ] && Tqual=$Pqual; shift 2;;
-Q) Tqual=$2; shift 2;; ##2009-11: scrapping Hqual allowed making -Q a single-opnd option (was 3-opnd)
## -S) Hsize=$2; Psize=$3; Tsize=$4; Pht=0; shift 4;; ##2009-11: scrapping Hsize made this obsolete; AREA: Pwd=Psize;Pht=Psize --> Pht=0
--PA) PadA=1; PadColor=black; shift;;
--PB) PadB=1; PadColor=black; shift;;
--PWA) PadA=1; PadColor=white; shift;;
--PWB) PadB=1; PadColor=white; shift;;
--N*) NOSZ=1; shift;;
--M*) MAXR=$2; shift 2;;
--F*) FULLDATE=1; shift;;
--CP*) CPYRIGHT=1; shift;;
--CA*) CAPANNO=1; FULLDATE=1; shift;;
--D*) DISTORT=1; shift;;
--PR*) PRF=$2; shift 2;;
--) shift;break;;
*) echo "$USAGE"; exit 2;;
esac
done
psize=$Psize; if [ $psize = - ];then psize=400; fi ##kluge for default Asize when Psize=-
if [ $Asize = -1 ];then ((Asize=9+psize/250)); fi ##default Asize is 9 + Psize/250; 2008-11-21 from 8+Psize/150 to 9+psize/250 w BOLD font
if [ $Amargin = -1 ];then ((Amargin=Asize*13/10)); fi ##default Amargin is Asize * 13/10; 2008-09-01 from 2 to 1.3
if [ $Aborder = -1 ];then ((Aborder=Asize*5/10)); fi ##default Aborder is Asize * 5/10; 2008-02-28 from 0.7 to 0.5
Psizeparm=$Psize
if [ $# -eq 0 ]; then set *.jpg; echo "defaulting to $(pwd)/*.jpg"; fi
while [ $# -gt 0 ]; do
##echo "--------------------------------------"
Psize=$Psizeparm
D=${1%/*}; [ "$D" = "$1" ] && D=$(pwd) ##get Directory-part of "original"-file $1
F=${1##*/} ##get $1 without directory-part, if any
b=${F%.*}; T=${F##*.} ##will use $b & $t to form filenames, e.g: Tiny=$PRF$b$Tsize.$t; Photo=$PRF$b$Psize.$t
if [[ $b == *_* ]]; then
while [ $b != ${b%[0-9]} ];do b=${b%[0-9]}; done ##--remove trailing digits from $b
fi
t=$Format ##ANY type now converted to JPEG - or as specified via -o option
##if [ "$T" == "png" ]; then Psize=720; Tsize=144; fi ##TEMP (used only for NOCI SE01-report)
##if [ "$T" == "png" ]; then t="gif"; fi ##may convert some to GIF (when #distinct colors is small)
##if [ "$T" != "gif" ]; then t="jpg"; fi ##others converted to JPG
##--need to use raw2ppm, for NEF files--
if [ "$T" == "nef" ];then raw2ppm $1; cp $D/$b.ppm tmp$$.ppm; T=ppm ##convert NEF to PPM; cameratopam now another option, based on dcraw=raw2ppm by Dave Coffin
else convert $1 tmp$$.ppm ##convert other to PPM
fi
##--get width and height
w=$(pnmfile tmp$$.ppm | gawk '{ print $4 }') ##could use identify -format %w
h=$(pnmfile tmp$$.ppm | gawk '{ print $6 }') ##could use identify -format %h
##m=$w; [ $h -gt $w ] && m=$h ##was: m=max(w,h) for size based on bigger dimension
m=$(echo "scale=20; sqrt($w*$h*4/3)" |bc -q) ##use: m=sqrt(w*h*4/3) for AREA-based size calculations with 4:3 ratio the norm
echo "---$1: ${w}x$h -- m=$m"
##--form filenames
if [ "$Psize" == "-" ]; then Psize=$w; Pwd=$w; Pht=$h; fi ##note: -p - => photo version same size as input image
Click="$b.$T"
Tiny=$PRF$b$Tsize.$t
if [ $NOSZ -eq 0 ]; then Photo=$PRF$b$Psize.$t; else Photo=$PRF$b.$t; fi
if [ $Psize -ne 0 ]; then Click="$Photo"; fi ##note: may be revised later, if -s option in effect
## ##--rescale original if required, so that size <= $Hsize (this is OBSOLETE)
## if [ $Hsize -ne 0 ]; then
## if [ "$T" != "$t" ] || [ $(echo "$m > $Hsize" |bc -q) -eq 1 ];then ##AREA: $m now non-integer
## echo "--replace the original? press any key to continue--"; read ##DEBUG; chance to ctrl+C abort
## R="1.0"; /bin/mv -f $D/$b.$T $D/$b.$T~
## if [ echo "$m > $Hsize" |bc -q -eq 1 ]; then
## /bin/mv -f tmp$$.ppm tmp$$-huge.ppm
## R=$(echo "scale=20; $Hsize/$m" |bc -q)
## pnmscale $R tmp$$-huge.ppm 2>/dev/null >tmp$$.ppm
## fi
## echo "Converting Huge Original: scale-factor $R, type $t, backup is $D/$b.$T~"
## convert -quality $Hqual tmp$$.ppm $D/$b.$t ##$T-->$t
## w=$(pnmfile tmp$$.ppm |gawk '{ print $4 }') ##could use identify -format %w -- for any image-type supported by ImageMagick
## h=$(pnmfile tmp$$.ppm |gawk '{ print $6 }') ##could use identify -format %h
## m=$(echo "scale=20; sqrt($w*$h*4/3)" |bc -q) ##AREA, was: m=$w; [ $h -gt $w ] && m=$h
## echo "$D/$b.$t: ${w}x$h -- m=$m" ##$T-->$t
## fi
## fi
##--produce Photo version (A) size $Psize, or (B) the smaller of Height-limited by $Pht, Width-limited by $Pwd.
if [ $Psize -ne 0 ]; then
if [ $Pht -eq 0 ]; then
R=$(echo "scale=20; $Psize/$m" |bc -q)
elif [ $DISTORT ];then ##2009-10: DISTORT option for exactly -s size
R="-xysize $Pwd $Pht" ##2009-10: does what my non-distorting -s code wants (YUP see man pamscale)
R="-xsize=$Pwd -ysize=$Pht" ##2009-10: for distorting exact-size
else
Rw=$(echo "scale=20; $Pwd/$w" |bc -q)
Rh=$(echo "scale=20; $Pht/$h" |bc -q)
R=$Rw; [ $(echo "$Rh < $Rw" |bc -q) -eq 1 ] && R=$Rh
##echo "Rw=$Rw Rh=$Rh R=$R" ##debug
fi
if ! [ $DISTORT ];then ##2009-10: with DISTORT option $R is not a number...
[ $(echo "$R>$MAXR"|bc -q) -eq 1 ] && R=$MAXR ##07mar: limit R to at most MAXR
[ $(echo "$R>1.5" |bc -q) -eq 1 ] && echo "==WARNING: UPSCALING BY $R" ##08aug: warn if upscaling by more than 1.5
fi
echo "Photo: scale by $R"
pnmscale $R tmp$$.ppm 2>/dev/null >tmp$$-R.ppm ##scale to make the Photo-sized ppm image
if [ "$PadB" = "1" ] && [ $Pht -ne 0 ]; then ##for BEFORE-annotation Padding to "size" with $PadColor
pw=$(pnmfile tmp$$-R.ppm | gawk '{ print $4 }')
ph=$(pnmfile tmp$$-R.ppm | gawk '{ print $6 }')
((L=(Pwd-pw)/2)); ((R=Pwd-pw-L))
((T=(Pht-ph)/2)); ((B=Pht-ph-T))
/bin/mv -f tmp$$-R.ppm tmp$$-Rprepad.ppm; pnmpad -left=$L -right=$R -top=$T -bottom=$B -$PadColor tmp$$-Rprepad.ppm >tmp$$-R.ppm ##FC4-version no longer accepts -lNBR -rNBR etc
fi
##---<<>>---
Aphotog=; Adate=;
Anm=${F%.*} ##Anm is: Caption[[_Location]_Date]_Photog[B][C]size was:Species[[[_Remark]_Location]_Date]...
Aphotog=${Anm##*_}; [ "$Aphotog" = "$Anm" ] && Aphotog=""
while [ "$Aphotog" != "${Aphotog%[-A-Z0-9]}" ];do Aphotog=${Aphotog%[-A-Z0-9]}; done ##03dec was: Aphotog=${Aphotog:0:2} --??
Anm=${Anm%_*}; ##Anm is: Caption[[_Location]_Date]
Adate=${Anm##*_}; [ "$Adate" = "$Anm" ] && Adate=""
Anm=${Anm%_*}; ##Anm is: Caption[_Location]
Aloc=${Anm##*_}; [ "$Aloc" = "$Anm" ] && Aloc="" ##2009-10: for Cap+Locn-in-annotation-text option
Anm=${Anm%_*}; ##Anm is: Caption ##2009-10: new
Acap=${Anm%%_*}; Anbr= ##Acap is: Caption ##2009-10: now keep both Acap and Aspecies
if [[ ${Acap:0:3} == [A-Z][A-Z][A-Z] ]];then ##2009-10: any 3 uppercase letters as nbr-prefix, eg:POD
Anbr=${Acap:3}; Anbr=${Anbr%%-*}; Acap=${Acap#*-}
elif [[ ${Acap:0:2} == [A-Z][A-Z] ]];then ##2009-10: any 2 uppercase letters as nbr-prefix, eg:ER
Anbr=${Acap:2}; Anbr=${Anbr%%-*}; Acap=${Acap#*-} ##05apr20: revised for the 57a sort of "numbers"
fi
##--had nice 2-digit-year kluges for my former non-numeric month; 07mar: added some that're useful with numeric month, but only before 2019--!!--
##--2008-02-28: modified 2-digit-year kluges to work with FULLDATE, by deferring & making conditional the truncation to 4-digit-year
[[ $Adate == [9-9][0-9][A-Za-z]* ]] && Adate=19$Adate ##kluge for 2-digit year, 9x => 19 in front (only useful with non-numeric month)
[[ $Adate == [0-8][0-9][A-Za-z]* ]] && Adate=20$Adate ##kluge for 2-digit year, 0x..8x => 20 in front (only useful with non-numeric month)
[[ $Adate == 9[0-9]* ]] && Adate=19$Adate ##kluge for 2-digit year, 9x => 19 in front
[[ $Adate == 0[0-9]* ]] && Adate=20$Adate ##kluge for 2-digit year, 0x => 20 in front
[[ $Adate == 1[0-8]* ]] && Adate=20$Adate ##kluge for 2-digit year, 1x => 20 in front, but only for x<=8
[[ $Adate == "" || $Adate == [1-2][0-9][0-9][0-9]* ]] || { echo "==$1==bad year:$Adate"; Adate=""; } ##07jan: invalid year => treat as date-unknown
if [ "$Adate" = "" ] && [[ $D == /pix/er* ]];then
Adate=20${D#/pix/er} ##dirname is /pix/erYYMMDD (except er02 not broken into er02MMDD dirs)
if [[ $D == /pix/er*-* ]];then Adate=""; fi ##eg: under /pix/er0610-AuntHelen-Photos => treat as date-unknown (may need some exceptions?)
fi
if [ ${#Adate} -gt 9 ];then ##2008-09-19: support Adate having Hour+Minute...
Adate=$(echo "$Adate" |sed 's|-\(..\)\(..\)| \1:\2|') ##2008-09-19: YYYYMMDD-HHMM to YYYYMMDD HH:MM
Adate=$(date -d"$Adate" "+%Y-%m-%d %H:%M") ##2008-09-19: then to YYYY-MM-DD HH:MM (was YYYY-MM-DD-HH:MM in TEMP OrigDate)
elif [ "$Adate" != "" ];then
Adate=$(datecvt "$Adate" %Y-%m-%d) ##2008-02+04: reformat date YYYYMMDD-->YYYY-MM-DD; date->datecvt to support alpha-month
fi
FullDate="$Adate" ##2008-04-15 keep fulldate for HTML-caption, even if annotating with Year-only...
if [ $FULLDATE -eq 0 ];then Adate=${Adate:0:4}; fi ##2008-02-28: w/o FULLDATE option, annotate with just 4-digit-year as before
##consider: if still no date, use date from photo-file => creative use of touch reqd for old rr+be photos + lots of other cases => dubious??
[ "$Aphotog" = "be" ] && Aphotog="Bud Ewacha"
[ "$Aphotog" = "rr" ] && Aphotog="Richard Reeves"
[ "$Aphotog" = "lr" ] && Aphotog="Laura Reeves"
[ "$Aphotog" = "hr" ] && Aphotog="Heather Reeves"
[ "$Aphotog" = "da" ] && Aphotog="Doris Ames"
[ "$Aphotog" = "aa" ] && Aphotog="Al Ames"
[ "$Aphotog" = "jw" ] && Aphotog="Jac Wiebe"
[ "$Aphotog" = "mw" ] && Aphotog="Mary Wiebe"
[ "$Aphotog" = "cz" ] && Aphotog="Carla Zelmer"
[ "$Aphotog" = "er" ] && Aphotog="Eugene Reimer"
[ "$Aphotog" = "pa" ] && Aphotog="Peggy BainardAcheson"
[ "$Aphotog" = "pb" ] && Aphotog="Peggy BainardAcheson"
[ "$Aphotog" = "jn" ] && Aphotog="John Neufeld"
[ "$Aphotog" = "lh" ] && Aphotog="Lorne Heshka"
[ "$Aphotog" = "bs" ] && Aphotog="Betty Siren"
[ "$Aphotog" = "rt" ] && Aphotog="Richard Tilley"
[ "$Aphotog" = "ar" ] && Aphotog="Allen Reimer"
[ "$Aphotog" = "cb" ] && Aphotog="Christie Burkowsky"
[ "$Aphotog" = "bk" ] && Aphotog="Bernie Kroemer"
[ "$Aphotog" = "bj" ] && Aphotog="Bob Joyce"
[ "$Aphotog" = "cn" ] && Aphotog="Chris Neufeld"
[ "$Aphotog" = "iw" ] && Aphotog="Ian Ward"
[ "$Aphotog" = "kd" ] && Aphotog="Kevin Duerksen"
[ "$Aphotog" = "jr" ] && Aphotog="Jim Roy"
[ "$Aphotog" = "bb" ] && Aphotog="Bruno Bergmans"
[ "$Aphotog" = "sb" ] && Aphotog="Sid Barkman"
[ "$Aphotog" = "jd" ] && Aphotog="john w dyck"
[ "$Aphotog" = "gf" ] && Aphotog="Geoff Fierce"
[ "$Aphotog" = "bf" ] && Aphotog="Bob Ferry"
if [[ $Aphotog == zz* ]];then Aphotog=""; [ $FULLDATE -eq 0 ] && Adate=""; fi ##for zz==Anon: DONOT annotate with name, with date only if FULLDATE in effect
[ ${#Aphotog} -gt 0 ] && [ ${#Aphotog} -lt 3 ] && { echo "==$1==unknown photographer:$Aphotog"; } ##used to also set Aphotog & Adate to emptystring??
Aphotog=$(echo "$Aphotog" | sed 's|~| |g') ##06may: replace tildes with spaces in Photog-name
if [[ $F == POD*_da* ]]; then ##--FOR SEED-PODS-BOOK; 2008-02-28 moved ahead of colour-picking; 2008-10: PB->POD as PB=>Peggy
Aphotog="Page $Anbr $Aphotog Seed Pod Identification" ##special-case annotation for seed-pods-book includes "Page..."
fi
COPY=; [ $CPYRIGHT -eq 1 ] && COPY='© ' ##2008-02-28 use of copyright-symbol controlled by CPYRIGHT option; 2009-09:8859-1-->utf8
if [ $CAPANNO ];then ##2009-10: CAPANNO option, for Cap+Locn-in-annotation-text
Atext=$(echo "$Acap $Aloc" |sed 's|--*| |g')
Atext="$Atext $COPY$Aphotog $Adate" ##considered: using "by " instead of $COPY
else
Atext=; [ "$Aphotog$Adate" ] && Atext="$COPY$Aphotog $Adate" ##2008-02-28 $Atext (in order to get its length) replaced $Aphotog $Adate
fi
##---<<>>---
if [ $Asize -ne 0 ] && [[ $F == *_* ]]; then ##==2010-01-03: moved IF here, so that Adate, FullDate, etc defined even if not annotating
##echo "Atext:$Atext; Acolor:$Acolor; PALE:$PALE;" ##==2008-04-23 DEBUG; for multiple images then an "_zz" anon one...
export DATE Photo ##2008-11-21 vars visible to annotatepix
if [ "$Atext" != "" ];then
annotatepix -f$Afont -a$Asize -c$Acolor -x$Amargin -y-$Aborder -t"$Atext" tmp$$-R.ppm ##2008-11-21 Photog+Date Annotation (bot)
fi
if [ $AsizeR -ne 0 ]; then ##Nbr+Species (on top) annotation; rarely used; used on SS-OrchidsThruYear slideshow
Aspecies=; C2B=/noci/com2both; [ -e $C2B ] && Aspecies=$($C2B $Acap |sed 's|.*(\(.*\)).*|\1|' |sed 's|||g; s|||g; s|×|x|g') ##2010-05 -e test
[[ $Aspecies == "" ]] && Aspecies=$Acap
((Atop=Aborder+AsizeR/2)) ##was ((Atop=Aborder+AsizeR-6))
Atext="$Anbr $Aspecies"
annotatepix -f$Afont -a$AsizeR -c$Acolor -x$Amargin -y$Atop -t"$Atext" tmp$$-R.ppm ##2008-11-21 Nbr+Species Annotation (top)
##convertOLD -font "-${Afont}-medium-r-normal-*-$AsizeR-*-*-*-p-*-iso8859-1" -fill $Acolor -draw "text $Amargin,$Atop \"$Atext\"" tmp$$-R.ppm tmp$$-R.ppm
fi
fi
##---<<>>---
if [ "$PadA" = "1" ] && [ $Pht -ne 0 ]; then ##for AFTER-annotation Padding to "size" with $PadColor
pw=$(pnmfile tmp$$-R.ppm | gawk '{ print $4 }')
ph=$(pnmfile tmp$$-R.ppm | gawk '{ print $6 }')
((L=(Pwd-pw)/2)); ((R=Pwd-pw-L))
((T=(Pht-ph)/2)); ((B=Pht-ph-T))
/bin/mv -f tmp$$-R.ppm tmp$$-Rprepad.ppm; pnmpad -left=$L -right=$R -top=$T -bottom=$B -$PadColor tmp$$-Rprepad.ppm >tmp$$-R.ppm ##FC4-version no longer accepts -lNBR -rNBR etc
fi
##--Get actual-size and recompute the $Photo output filename; was being done only if $Pht nonzero (-s specified)
##--now do in all cases, since sizes sometimes miss by 1 due to rounding to integers--??
##--05jun: this name-picking was before annotation (prior to PadA option); doing here is ok wrt resulting filenames,
##-- but means some incorrect names written to the ANNOTATIONS log--!!--
pw=$(pnmfile tmp$$-R.ppm |gawk '{ print $4 }')
ph=$(pnmfile tmp$$-R.ppm |gawk '{ print $6 }')
pm=$(echo "scale=20; sqrt($pw*$ph*4/3)" |bc -q) ##AREA, was: pm=$pw; [ $ph -gt $pw ] && pm=$ph
pM=$(echo "scale=0; ($pm+5)/10*10" |bc -q) ##AREA: round $pm to multiple of 10
pm=$(echo "scale=0; ($pm+0.5)/1" |bc -q) ##AREA: round $pm to integer
((Pht==0)) && ((pm!=Psize)) && echo "====RequestedSize=$Psize ActualSize=$pm"
if [ $NOSZ -eq 0 ]; then
Photo=$PRF$b$pm.$t; Click=$Photo; ##revise $Photo & $Click names w actual-size; 2010-01-05: for -M limited too, was for -s only
fi
##
##--Write the Photo version:
##--2004jan: alternatives to convert; 2008-11-22: "to gif" via Netpbm now done here, and have scrapped /etc/sbin/convert script
if [ "$t" = "ppm" ]; then
cat tmp$$-R.ppm >$Photo ##trivial to-PPM case
elif [ "$t" = "gif" ]; then
ppmquant 256 tmp$$-R.ppm |ppmtogif >$Photo ##netpbm routines to convert to GIF, in order to get compressed-gif
elif [ "$t" = "jpg" ]; then
##ppmtojpeg -quality=$Pqual tmp$$-R.ppm >$Photo ##2004jan: ppmtojpeg to get UNSPECIFIED density-units
##--2006jun: compute dpi so image fits within a 10x7.5 inch page; was TEMP for KPLReimer (10x7-inch) photos - may make it an option==??==
dw=$(echo "scale=0; ($pw+5.00)/10.0" |bc -q)
dh=$(echo "scale=0; ($ph+3.75)/7.5" |bc -q)
dpi=$dw; ((dh>dw)) && dpi=$dh ##2006jun: take max of width/10 and height/7.5 (rounded to integer) as the DPI
pnmtojpeg -quality=$Pqual -density=${dpi}x${dpi}dpi tmp$$-R.ppm >$Photo ##2006jun: use pnmtojpeg w -density option to SPECIFY density+units
elif [ "$t" = "tif" ]; then
convert +compress tmp$$-R.ppm $Photo ##2004jan: override convert's default of compressed-tiff's
else
convert -quality $Pqual tmp$$-R.ppm $Photo ##before the 2004jan alternatives-to-convert
fi
fi
##--produce Tiny/Thumbnail version, size $Tsize
if [ $Tsize -ne 0 ]; then
R=$(echo "scale=20; $Tsize/$m" |bc -q)
echo "Thumb: scale by $R"
pnmscale $R tmp$$.ppm 2>/dev/null >tmp$$-R.ppm
convert -quality $Tqual tmp$$-R.ppm $Tiny
fi
##--write to the HTML files
b=${b%_*}; b=${b%_*} ##2008-04-15 $b is base-filename without _DATE_PHOTOG
CAPN=$b;LOCN=; if [[ $b == *_* ]];then LOCN=${b##*_}; CAPN=${b%_*}; fi ##2008-04-15 get caption & location
[ $Tsize -eq 0 ] && Tiny=$Click ##2010-01-03 so Thumbs-page is useful, even when not making Thumbnails
##ho "
" >>$Thumbs ##Thumbs-page - until 2009-12-29
echo "
" >>$Thumbs ##2009-12-29 Thumbs-page, with class=thumb
echo "
${CAPN#*-} -- $FullDate
" >>$Photos ##2008-04-15 Photo-page with TEMP(Inuvik) caption
##ho "
$CAPN - $LOCN - $FullDate
" >>$Photos ##2008-04-15 Photo-page with full caption
##ho "
$LOCN - $FullDate
" >>$Photos ##2008-04-15 Photo-page with short caption
echo "$Click" >>$Pnames
shift
done
rm tmp$$*.p?m ##YANK to debug using tmpfiles
exit
===========
CHANGE-LOG:
===========
2001-Oct: originally loosely based on a script called scale-make by Matt Giwer, April 2001, jull43@tampabay.rr.com, www.giwersworld.org;
but with the following changes:
(1) optionally produce "Photo" version, as well as Thumbnail -- controlled by the -p option;
when used, the Thumbnail-page link will be to this "Photo" version;
(2) annotate Photo version with photographer-name & year (from the filename); controlled by params for font-size etc;
optionally (-r), annotate with Remark as well -- also from the filename;
NOTE: point (2) would need changes for anyone else: naming-conventions, photographer-abbreviations ...
NOTE: have made a lot of other changes, most notably the smart colour-picking for annotation-text (in annotatepix now a separate script).
2001-Oct: briefly used options: -S for 360px; -M for 450px versions; but replaced these with -p option,
to enable custom sizes, although losing the ability to make two sizes with single invocation;
also briefly used one letter size-info in filename: T for 50-199px S for 200-379px M for 380-599px L for 600-999px;
but now use NumberPixels in the filename (e.g. allows both 450px and 520px sizes of same photo)
2003-Apr: (for slideshows) support -s size-specification
2003-July: ==AREA== size-calculations are now AREA-based (with 4:3 aspect-ratio being the norm),
so that a size of 400 means having the area of a 400x300 picture (formerly meant bigger dimension was 400);
this becomes important for pictures with unusual HW-ratios like square or very thin (e.g. my cropped 2003-FolkFest photos);
NOTE: the -s option became more of a special-case; the changes are flagged with "AREA" comments;
2003-Sep: revised the default left-margin for annotations (-m)
2003-Sep: support '-' as the -p operand, to mean same size as input photo
2004-Jan21: attempted KLUGE to revise DPI info in JFIF-JPEG-header -- for BobFerry -- BUT GAVE UP due to Unix-utils (sed etc) inability to handle x00 chars:-(
--JFIF header fields: JFIF 00 Vers Units Xden Yden
--note: image written by has: JFIF 00 0101 01 0001 0001 -- Units=01 => DPI, so this is 1x1DPI which is bloody awful --!!--
--note: image written by has: JFIF 00 0101 00 0001 0001 -- Units=00 => Unspecified, as wanted
set -xv
echo "trying klugey sed method to modify JFIF header DPI fields" ##tough due to x00 involved
echo 's|JFIF\(.....\).\(.\).|'$'JFIF\\1\x96\\2\x96|g;' >tmp-sedcmd
ppmtojpeg --quality=$Pqual tmp$$-R.ppm | sed 's|JFIF\(.....\).\(.\).|'$'JFIF\\1\x96\\2\x96|g;' >$Photo ##kluge: revise 1x1 to 150x150 in DPI part of JFIF-header
--solution was to switch from ImageMagick-convert to ppmtojpeg;
2004-Dec: lost mods made between 2004Aug and 2004Nov, namely:
- an option to control the Padding for slideshows (-s W H option) -- reintroduced as the -PA or -PB option
- producing Pnames file, like Photos.htm except has just the photo-sized filenames -- reintroduced
2005-July: revised the naming conventions: the "editing letters" after photographer-initials can now include digits & hyphen,
e.g. _erCE-00SHARP
(==need to revise WEBSCALE etc accordingly==)
2005-Oct: Fedora FC4 again broke this script (more notes on FC1,FC4 problems in annotatepix):
3) used Helvetica instead of Verdana until I'd installed fonts -- 2006-Apr: back to Verdana
4) its pnmpad has non-compatible parameter changes -- only noticed (2006may) when next using -PA padding for a slideshow
5) its pnmpad is broken in another way: it pads by 1 on bottom when no padding requested?? ==investigate further==!!==
2006-May: support tilde "~" in a photographer-name to be replaced by space;
sometimes use "_zzPersonsName" when photographer is known, but the photo is already annotated -- was already supported.
2006-Jun: default Amargin now Asize*2, rather than 20 -- handier for annotating large "slideshow" pictures; 2008-08: Asize*13/10 even better
2008-02-28: default Aborder now 7/10ths Asize, rather than 7; remains consistent with previous for website use, and means less need to specify -b for slideshows;
(used to need even bigger on SLIDESHOWs, because the POWERPOINT-slideshow-plugin truncates a wee bit on bottom, depending on image-type?)
2008-08-25: made Asize default depend on Psize; had thought it dubious, but the need became perfectly clear when I went to size720 on my website;
want Asize=10 for sz300..400, 10/11 for 520, 12 for 720 ==> 8 + Psize/150 achieves that;
considered: 6 + Psize/100: 300..399->9, 4xx->10, 5xx->11, 6xx->12, 7xx->13, .. 10xx->16
went with: 8 + Psize/150; 300..449->10, 450..599->11, 600..749->12... 900..1049->14
--tried: 7 + Psize/150; 300..449->9, 450..599->10, 600..749->11... 900..1049->13 <--after switching to BOLD default
==WENT TO: 9 + Psize/250: 250..499->10, 500..749->11, 750..999->12, 1000..1249->13 <==after switching to BOLD default==
==After switching to BOLD fonts: want 10 for 380, want 11 for sz740 ==>need divisor at least 250...
2008-08-30: issue Warning when Upscaling by more than 1.5; NOTE: webmake, WEBSCALE will never get the warning since they specify a smaller MAXR;
considered a MAXR default, but that seems wrong for general-purpose use;
consider: apply BLUR when upscaling by more than 1.5--??--
2008-11-17: needed: filename-revision when scale-factor limited by MAXR (am getting "Requested-Size vs Actual-Size" warning-msg);
first had to revise WEBSCALE script -- done 2008-11-17, it now computes the MAXR-limited size, and supplies the correct -p param to scalepix;
2010-01-05: finally did the easy part here;
2008-11-21: made annotatepix a separate script (this script decides on the annotation-text, and on the X/Y-coords);
revised defaults: font now verdana-bold; fontsize now smaller, see above; Note: fractional sizes would be possible with new method...
default-fontsize-picking for case like -s 780 555 now uses Height*4/3, to behave like -p 740;
2009-03-21: added -PWA -PWB options for Padding-With-White
CONSIDER: support option with or without space before operand; nice but bloody painful to do in shell-language==??==
CONSIDER: new -PAW|-PBW Pad-With-White options, -PAW needed for mk-operashow (was briefly needed...)
CONSIDER: make FULLDATE the default -- replace with YEARONLY option (==first revise old Rich "dates" to -RRrollnumber_YEAR)
==!!==FIXME: on NOCI site, rename the old Rich "dates" which are YEAR+ROLLNUMBER so they can be re-annotated; NOTE: _199820xx presently becomes 1999==!!==
2009-09: UTF-FIXUP on COPY (copyright-symbol); was $'\xa9' now using '©' in utf8;
2009-10: new options needed for mk-calendar-8up-wallet-sized:
(1) -DISTORT option -- distort to exactly the -sWxH size;
(2) -CAPANNO option -- annotate with Caption+Location PHOTOG YYYY-MM-DD (with hyphen(s) to space)
(3) -PREFIX option -- specifies string to be prefixed to resulting Photo-filename
considered tmp$$-->tmp$b to be handier for multiple annotations; then realized that using -o ppm is a better way:-)
2009-11: yanked the H-resizing code, making Hsize, Hqual obsolete; yanked -h; considered -Q -S becoming 2-opnd options, but then getopt led to further changes;
2009-11-20: getopt cmdline-option-parsing; getopt lacks multiple operands => revise my -s -Q -S options wrt multiple operands;
-s now single operand in the NBRxNBR style; -S scrapped; -Q replaced by single-opnd option for Tqual; ==note: -p and -s could now be combined==??==
after-getopt-loop revised to use DOUBLE-DASH on long-options;
==note: previous uses of -M 1.5 can now be written as -M=1.5 (but not as -M1.5) because it's a LONG-option...
--scripts invoking scalepix with -Q and/or -S:
fixscannedtext: <--have revised, though long unused...
--scripts invoking scalepix with -s:
mk-calendar-8up-wallet-sized <--these were -s $VAR $VAR
mk-calendar-covers <--these were -s $VAR $VAR
mk-operashow <--some with extra spaces were fixed manually
mk-webpage-InuvikTrip-prelim
send-photos-by-name-or-number-annotated <--nontrivial fixup to: VAR=${VAR}x$VAR; scalepix -s$VAR
shopping-image-renames-for-ImgColumnOption
annotatepix img2pdf mk-webpage-InuvikTrip-final scalepix <--these invocations were in comments, but needed fixing just the same
--revising: chgsed -p '/scalepix.* -s [0-9]/s| -s \([0-9][0-9]*\) \([0-9][0-9]*\)| -s\1x\2|' *
--revising: chgsed -p '/scalepix.* -s \$/s| -s \$\([^ ][^ ]*\) \([^ ][^ ]*\)| -s${\1}x\2|' *
--noticed flaw in OLDwebcopy -- see notes in /er/CHANGES;
2009-12-02: revised calls to annotatepix, its -c now takes optional-opnd (double-colon to getopt); ie: opnd must now come immediately after -c;
2009-12-29: Thumbnail-page, replaced align=middle border=0 hspace=1 vspace=10 with class=thumb; --see notes in: /er/color-schemes-HISTORY
on ER-site: converted all per-day pages this way, in nav1: img.thumb {border-style:none; padding:0; margin:8px 2px; vertical-align:middle;}
genByCaption-ER: same revision, applies to ANON-pixsearch...
2010-01-03: make tmpThumbs moderately useful even when no Thumbs being made;
FullDate needed even if not annotating, for the Photos-page; done;
2010-01-05: revised $Photo & $Click names using actual-size; now done in all cases since also wanted for -M limited size; was only being done if -s specified;
thought I'd done this long ago, but hadn't;
==renaming-by-size needed for images on my site -- did this once before, now only need to look at "720" ones;
==eg: http://ereimer.net/20090601/RF1080845_Pinawa_20090601_Ron~Friesen720.htm <--is a mere 320x240==!!==
2010-05-08: moved Aspecies computation into the "if $AsizeR -ne 0" part; added existence-test on /noci/com2both which most people won't have;
==webcheck-bashscripts, my checker of published scripts for missing PREREQS, ought also to check for fully-qualified filenames; (see notes in it & webput)