#!/bin/bash
## script to regenerate the Frontpage-Images, and revise the javascript arrays-of-filenames in index.htm page; Eugene Reimer 2010-01-03;
## PREREQ: ATTRIBS chgtr -- from http://ereimer.net/programs/general-purpose-scripts.htm
ME="
/pix/er030602/MeAtFlowerpotIsland_2003jun01_daBCC.jpg /pix/er030602/02381_erCCCB.jpg
/pix/er030611/02616_daC.jpg /pix/er030919-Doris/MeAtBaldyMtn_2003jun24_rrCC.jpg
/pix/er040714/MeOnBridge_PisewFalls_2004jul14_daCCCSC-SQUARE.png /pix/er040714/MeOnBridge_PisewFalls_2004jul14_daCVSC-SQUARE.png
/pix/er050513/07846_daC2B.jpg /pix/er050513/07846_daCC.jpg
/pix/er080706/DA00666_20080706_daCC.jpg /pix/er090910/DA02129-Eugen+CannabisPlant_20090910_da.jpg
/pix/er080624/DA00128_20080624_daC.jpg /pix/er080624/DA00128_20080624_daCBR.png /pix/er080627/DA00251_20080627_daC.jpg
/pix/er080627/DA00251_20080627_daCCB.jpg /pix/er080629/DA00319_20080629_daCBR.jpg /pix/er080629/DA00325_20080629_daCC.jpg
/pix/er080629/DA00341_20080629_zzCB.jpg /pix/er080701/DA00491_20080701_daCBE.jpg /pix/er080715/DA00961_20080715_daX.jpg
/pix/er080715/DA00961_20080715_daCC.jpg /pix/er030610/02595_jn.jpg /pix/er070302/Eugene-atPCESCinRegina-PB3633_zzCC.jpg
/pix/er030607/02451_daC.jpg /pix/er030607/02451_daCC.jpg /pix/er070524/10836_daCB.jpg /pix/er100615/17200_daC.jpg
"
OT="
/pix/er02/Zf14f_er.jpg /pix/er030512/01751_er.jpg /pix/er030602/02100_er.jpg /pix/er030809/03936_erCC.jpg /pix/er040506/04945_erBCC.jpg
/pix/er040603/05297_erCCS.png /pix/er040603/05321_erBXCC.jpg /pix/er040603/05321_erCC.jpg /pix/er040622/05735_erBC.jpg /pix/er040715/06407_erCCB.jpg
/pix/er040718/06805_erC.jpg /pix/er050811/08818_erCB.jpg /pix/er070811/11684_erC.jpg /pix/er080612/12490_erC.jpg
/pix/er080621/12693_erC.jpg /pix/er080707/13737_erCBS.jpg /pix/er080708/13759_erCBS.jpg /pix/er080709/13862_erCB.jpg /pix/er080811/14438_erCB.jpg
/pix/er080906/14686_erC.jpg /pix/er080918/14743_erCCB.jpg /pix/er080918/14744_erC.jpg /pix/er090208/14784_erCB.jpg /pix/er090507/15042_erCB.jpg
/pix/er090507/15066_erCB.jpg /pix/er090516/15117_erCB.jpg /pix/er090516/15124_erCS.jpg /pix/er090523/15194_erCC.jpg /pix/er090604/15255_erC.jpg
/pix/er090613/15387_erC.jpg /pix/er090620/15529_erCS.jpg /pix/er090620/15545_erCC.jpg /pix/er090620/15566_erC.jpg /pix/er090630/15633_erC.jpg
/pix/er090630/15637_erCB.jpg /pix/er090701/15703_erCB.jpg /pix/er090701/15722_erCCB.jpg /pix/er090729/16082_erC.jpg /pix/er090808/16194_erCB.jpg
/pix/er090808/16194_erCBC.jpg /pix/er090817/16221_erCB.jpg /pix/er090911/16295_erC.jpg /pix/er090913/16330_erC.jpg
/pix/er040721/07146_erC.jpg /pix/er040715/06415_erCC.jpg /pix/er040506/04896_erBC.jpg /pix/er040716/06478_erC.jpg /pix/er040714/06264_erC.jpg
/pix/er030512/01786_er.jpg /pix/er030702/03188_erBSC.png /pix/er030705/03276_erCCC.jpg /pix/er030705/03278_erC.jpg /pix/er030705/03313_erC.jpg
/pix/er030705/03320_erCBS.jpg /pix/er030719/03641_erCCCCB.png /pix/er030803/03818_erC.jpg /pix/er030803/03834_er.jpg /pix/er030803/03847_erC.jpg
/pix/er030803/03867_erC.jpg /pix/er030809/03940_erCC.jpg /pix/er030809/04074_erC.jpg /pix/er040508/04965_erBC.jpg /pix/er040707/05883_erC.jpg
/pix/er040715/06416_erCC.jpg /pix/er040717/06663_erCCBA.jpg /pix/er040719/06883_erCC.jpg /pix/er040817/07414_erC.jpg /pix/er050617/08164_erCCB.jpg
/pix/er050628/08457_erC.jpg /pix/er050721/08693_erCC-SHARP.jpg /pix/er050813/08928_erCS.jpg /pix/er060611/09811_erCB.jpg /pix/er060611/09817_erCBS.jpg
/pix/er060808/10098_erCCS.jpg /pix/er060817/10204_erCBS.jpg /pix/er070614/11159_erCBS.jpg /pix/er070629/11463_erC.jpg /pix/er070629/11517_erCBS.jpg
/pix/er070714/11620_erCB.jpg /pix/er070811/11701_erCCBA.png /pix/er070811/11712_erCCB.jpg /pix/er080616/12620_erS.jpg /pix/er080616/12624_erCBS.jpg
/pix/er080625/12765_erCB.jpg /pix/er080627/12963_erC.jpg /pix/er080704/13517_erC.jpg /pix/er080705/13552_erCS.jpg /pix/er080705/13559_erCCB.jpg
/pix/er080711/14060_erCS.jpg /pix/er080716/14349_erC.jpg /pix/er080716/14358_erCB.jpg /pix/er080807/14418_erCBS.jpg /pix/er090616/15413_erC.jpg
/pix/er090630/15601_erCC.jpg /pix/er090704/15860_erC.jpg /pix/er090704/15882_erCC.jpg /pix/er090727/15993_erC.jpg /pix/er090729/16066_erC.jpg
/pix/er090730/16109_erC.jpg /pix/er040722/07167_erCCCB.jpg
/pix/er070314/10407_erCCES.jpg /pix/er050505/07811_erC.jpg /pix/er040527/05131_erBC.jpg /pix/er040527/05136_erBC.jpg /pix/er040622/05711_erBC.jpg
/pix/er070522/10686_erC.jpg /pix/er070523/10720_erCCCB.jpg /pix/er070524/10832_erCCB.jpg /pix/er070629/11445_erC.jpg /pix/er040622/05682_erBC.jpg
/pix/er040622/05704_erC.jpg /pix/er050811/08782_erC.jpg /pix/er080705/13578_erCBS.jpg /pix/er030809/04097_erC.jpg /pix/er030822/04290_erC.jpg
/pix/er070523/10794_erCBS.jpg /pix/er060527/09625_erCB.jpg /pix/er060527/09623_erC.jpg /pix/er080711/14112_erC.jpg /pix/er080626/12831_erC.jpg
/pix/er080711/14022_erCB.jpg /pix/er080627/12864_erX.jpg /pix/er080711/14166_erC.jpg /pix/er090704/15774_erC.jpg /pix/er080711/14196_erC.jpg
/pix/er030821/04229_erC.jpg /pix/er040716/06562_erC.jpg /pix/er091018/16659_erCB.jpg /pix/er091018/16670_erC.jpg /pix/er070526/10973_erC.jpg
/pix/er040713/06195_erC.jpg /pix/er080823/14590_erCB.jpg /pix/er030609/02554_er.jpg /pix/er030609/02564_er.jpg /pix/er040523/05092_erBCC.jpg
/pix/er100522/16917_erCCB.jpg /pix/er100522/16967_erCB.jpg /pix/er100605/17109_erC.jpg /pix/er100605/17113_erCB.jpg /pix/er100615/17211_erC.jpg
/pix/er100708/17233_erCB.jpg /pix/er100712/17299_erC.jpg /pix/er100712/17308_erCC.jpg /pix/er100712/17322_erC.jpg /pix/er100718/17358_erC.jpg
/pix/er100525/17012_erC.jpg /pix/er100411/16781_erCB.jpg /pix/er100509/16835_erCC.jpg /pix/er100518/16898_erC.jpg /pix/er100525/16988_erCCB.jpg
/pix/er100528/17018_erC.jpg /pix/er100528/17026_erC.jpg /pix/er100603/17064_erC.jpg /pix/er100605/17128_erC.jpg
"
cd /er/website || exit ##==work in /er/website dir
echo "genFrontpageCandidates-ER: redoing frontpage-images" ##msg
##genByCaption-ER ##caption-file update; YANKED, now called from webput...
rm -f FP[MO]-*jpg tmp* ##new prefix-naming makes this safe enough
scalepix -a0 -t0 -s999x150 -PRF=FPM- -M=1.0 $ME ##scale ME imgs to height:150 prefix:FPM MAXR:1
scalepix -a0 -t0 -s999x150 -PRF=FPO- $OT ##scale OT imgs to height:150 prefix:FPO
byAspectRatio () { ATTRIBS "$@" |sort -k6 |arr 1 |sed 's|:$||'; } ##==byAspectRatio: function
cvt2imgtag () { ##==cvt2imgtag: function
while read -r;do ##for each imgname...
B=$(echo "$REPLY" |sed 's|FP.-||; s|[0-9]*.jpg||') ##get imgname w/o prefix, w/o sz.jpg
I=$(grep "[=/]$B[0-9]" ANON-pixsearch.txt |sed "s|]*>||; s|||; s|=.*$B.*jpg|=$REPLY|") ##get its line in ANON-pixsearch.txt, cvt to just IMG-tag
[[ $I == "" ]] && echo "==$B not found in ANON-pixsearch.txt" >&2 ##warn if not found
echo "$I" |sed "s|'|\\\\'|g" ##produce IMG-tag line, escaping strophs
done
}
byAspectRatio FPM-*jpg |cvt2imgtag >tmpME ##tmpfile of me-imgtags
byAspectRatio FPO-*jpg |cvt2imgtag >tmpOT ##tmpfile of other-imgtags
{ echo "
Of-Me Candidates:
"; cat tmpME; ##was: grep '=FPM-' tmpThumbs.htm |sed 's|]*>||; s|||'
echo "Other Candidates:
"; cat tmpOT; ##was: grep '=FPO-' tmpThumbs.htm |sed 's|]*>||; s|||'
} >ANON-FrontpageCandidates.htm ##produce Frontpage-Images page
meIMG=$(cat tmpME |sed "s|.*|'&'|" |tr '\n' ',') ##meIMG gets list of me-imgtags
NTOT=$(wc tmpOT |arr 1); ((N=(NTOT*2+5)/10)) ##divide NTOT by 5 rounded, eg when NTOT==44 then N==9
otIMGA=$(head -n$N tmpOT |sed "s|.*|'&'|" |tr '\n' ','); chgsed -q -n "1,${N}d" tmpOT ##otIMGA gets list of first N other-imgtags
otIMGB=$(head -n$N tmpOT |sed "s|.*|'&'|" |tr '\n' ','); chgsed -q -n "1,${N}d" tmpOT ##otIMGB gets list of next N other-imgtags
otIMGC=$(head -n$N tmpOT |sed "s|.*|'&'|" |tr '\n' ','); chgsed -q -n "1,${N}d" tmpOT ##otIMGC gets list of next N other-imgtags
otIMGD=$(head -n$N tmpOT |sed "s|.*|'&'|" |tr '\n' ','); chgsed -q -n "1,${N}d" tmpOT ##otIMGD gets list of next N other-imgtags
otIMGE=$(cat tmpOT |sed "s|.*|'&'|" |tr '\n' ',') ##otIMGE gets list of rest of other-imgtags; handles NTOT!=N*n
meIMG=${meIMG%,};otIMGA=${otIMGA%,};otIMGB=${otIMGB%,};otIMGC=${otIMGC%,};otIMGD=${otIMGD%,};otIMGE=${otIMGE%,}; ##remove trailing commas
JS="meIMG=[$meIMG]; otIMGA=[$otIMGA]; otIMGB=[$otIMGB]; otIMGC=[$otIMGC]; otIMGD=[$otIMGD]; otIMGE=[$otIMGE];" ##express as JS-array-vars
##echo "NTOT:$NTOT N:$N; JS:$JS" |sed 's|; |;\n\n|g'; read ##DEBUG
INDEX=index.htm ##was newfrontpage.htm for initial testing
chgsed -q -T "/^meIMG=/,/\/SCRIPT>/c$JS\v" $INDEX ##revise xxIMG vars in index.htm (use -p in testing)
chgtr -q -T '\v' '\n' $INDEX ##must be on at least 2 lines; better way??
rm -f tmp* *~ ##cleanup; YANK when testing
exit
--early notes are in: /pix/er-frontpage-images/00-NOTES-ON-CREATING-OR-ADDING-IMAGES <==that DIR now obsolete except for those notes;
--fixed trailing-comma; the reason IE sometimes had broken-image??
--index.htm: added note about Refresh/Reload for new random-selection; added NOSCRIPT section; added subtle sitemap-link for local-testing: links as in old frontpage;
--using prefix "FPM-" and "FPO-" to make matching easier & safer; via scalepix --PRF option;
--rewrote with ME, OT vars containing the SRC-imgnames => no longer using copy+rename under /pix/er-frontpage-images dir;
--added TITLE tags, to have hover-captions; get from ANON-pixsearch.txt w/o pref|sz-matching; =>any specially-cropped must be "up";
any specially-cropped variant stays in its original dir; must be "up", so Caption will exist in ANON-pixsearch.txt (matching w/o sz);
--put up: DA00666-me-in-the-RobertService-chair_DawsonCity-YT_20080706_daCC190.jpg
--put up: MeOnBridge_PisewFalls_20040714_daCCCSC-SQUARE170.jpg --MeOnBridge_PisewFalls_2004jul14_daCVSC-SQUARE
--put up: Calypso-05297_erCCS
--put up: 06407_erCCB720.jpg
--added new DORIS selections, for OT:
/pix/er040721/07146_erC.jpg
/pix/er040715/06415_erCC.jpg
/pix/er040506/04896_erBC.jpg
/pix/er040716/06478_erC.jpg <--may omit?? is an "ok" Calypso, but already have a Calypso and have better ones??
/pix/er040714/06264_erC.jpg
--added formerly-used-on-frontpage, for ME:
Me+hat-Zc09f_20020725_daC <--simplified name to Zc09f_20020725_daC; --OMIT; not good at more than 100px-high, and have enough face+hat shots:-)
MeAtFlowerpotIsland_2003jun01_daBCC <--put up
MeOnStump-07846_20050513_daC2B <--simplified name to 07846_daC2B; also added the CC crop as another candidate
--added new DORIS selections, for ME:
/pix/er030919-Doris/MeAtBaldyMtn_2003jun24_rrCC.jpg <--new crop: CC
/pix/er030602/02381_erCCCB.jpg <--new crop: CCCB
==Random-Seed==??==
now = new Date();
seed = now.getSeconds();
var randomFookie = Math.floor((Math.random(seed) * myFortune.length));
2010-01-06:
fixed grep-pattern to avoid duplicates in tmpME, tmpOT, ANON-FrontpageCandidates.htm, JS-arrays -- more than one crop of same photo was being matched;
2010-01-07:
ADDED MY PICKS for: beetle/stinkbug/butterfly/monarch/moth/skipper/larva/caterpillar/spider/woodtick/turtle/owl/fox/ptarm/calopogon/blue-lettuce/primrose/syrphid:
20050617/08164_erCCB Tigger Beware of Cat!
20090729/16066_erC powwow-dancer
20030705/03276_erCCC dogbane beetle
20030705/03313_erC stinkbugs mating
20080627/12963_erC stinkbug on my finger
20070714/11620_erCB Six-banded longhorn-beetle=Dryobius sexnotatus and BandedHairstreakButterfly on Fleabane
20080807/14418_erCBS Cucumber beetle mating pair <==smaller crop??
20040817/07414_erC Trichiotinus assimilis=a flower beetle on Meadowsweet=Spiraea~alba
20090704/15882_erCC Trichiotinus assimilis=a flower beetle on Rose 2nd flower
20060611/09811_erCB Black ground-beetle several on CanadaAnemone
20060611/09817_erCBS Solier beetle <--Soldier; --NOW:Firefly=Ellychnia corrusca
20030705/03278_erC Pearl-crescent butterfly on OxEyeDaisy
20030809/04074_erC Fritillary butterfly w bee on JoePye
20040508/04965_erBC Mourning cloak-butterfly
20040707/05883_erC White admiral butterfly
20050628/08457_erC White admiral butterfly
20050813/08928_erCS Milberts tortoiseshell butterfly on Goldenrod
20060808/10098_erCCS Fritillary butterfly GreatSpangledFritillary=Speyeria_cybele on Goldenrod
20070614/11159_erCBS Monarch butterfly pair mating male on top
20080704/13517_erC Blue butterfly in Inuvik
20080711/14060_erCS White admiral butterfly at Laird HS
20080716/14358_erCB Northern pearly-eye butterfly=Enodia anthedon on Coltsfoot at WagnerBog
20090616/15413_erC Tiger swallowtail butterfly
20090730/16109_erC Pearl-crescent butterfly=Phyciodes tharos on Smooth aster
20030803/03818_erC Monarch on MeadowBlazingStar
20030803/03867_erC Monarch chrysalis semi-transparent on Milkweed
20030803/03847_erC Monarch caterpillar on Milkweed
20030809/03940_erCC Monarch on JoePye
20070629/11517_erCBS Hummingbird moth=clear-wing sphinx-moth=Hemaris thysbe on Dogbane --new crop
20080716/14349_erC Inchworm moth=Scopula sp at WagnerBog
20090630/15601_erCC Eight-spotted forester moth closer
20090727/15993_erC Spurge hawkmoth=Hyles euphorbiae caterpillar closer
20030719/03641_erCCCCB Dun skipper=Euphyes vestris on SmallPurpleFringedOrchid (psyche on psycodes)
20030705/03320_erCBS Skipper mating --new crop
20070811/11712_erCCB Yellow-bear caterpillar larva of a tiger-moth (Family Arctidiiae) on JoePyeWeed --new crop
20050720/08693_erCC-SHARP Tobacco hornworm=Manduca sexta caterpillar computer-enhanced <--found in /pix/er0721
20070811/11701_erCCBA Monarch pair mating on blazing-star brighter --new crop
20040717/06663_erCCBA Common dock spider with blue egg-sac brighter --new crop
20060817/10204_erCBS Banded argiope spider=Argiope trifasciata another view
20080616/12620_erS Furrow orb-weaver=Larinioides-cornutus(Araneidae-family) red+black spider with web
20080616/12624_erCBS Furrow orb-weaver=Larinioides-cornutus(Araneidae-family) red+black spider closeup
20080625/12765_erCB Crab spider closer near Mayerthorpe-AB
20090704/15860_erC Crab spider at Portage Sandhills
20030512/01786_er Painted turtle
20070629/11463_erC Painted turtle foot
20080705/13552_erCS Great grey owl near Inuvik
20080705/13559_erCCB Red fox kit near Inuvik
20040719/06883_erCC Willow ptarmigan chick closer --new crop
20030702/03188_erBSC Calopogon crop --new crop
20030803/03834_er Blue lettuce flower
20040715/06416_erCC Greenland primrose flowers at CapeMerry
20040721/07167_erCCCB Syrphid-fly=Microdon sp on Camas tight crop <--found in /pix/er040722
--revising: arr 1 |sed 's|^20|d -1 /pix/er|; s|$|.*|' <--worked for above, except for 2 as noted above involving multi-day pages;
==NEED: easier way to add images,
eg: easily provided form: 20090729/16066_erC <--where the original to be used is: /pix/er090729/16066_erC.jpg
2010-01-07: FIXED: now backslashing apostrophes in captions; eg "at Iris's place" caused invalid Javascript otherwise;
2010-01-07: sort by Aspect-Ratio, before breaking into equal-sized groups -- doesn't matter if a common shape straddles 2 groups;
to greatly reduce variation in total-width for the row-of-five;
note: my narrowest group has AspectRatios from .45 to .85; central 3 groups: .85 to 1; 1 to 1; 1 to 1.33; widest group from 1.33 to 2.2;
--see: /er/FrontPageImages-by-shape; 101 images;
--Doris:
20070314/10407_erCCES Monarch egg on Milkweed
20050505/07811_erC ?unidentified cocoons?
20040527/05131_erBC Early blue violet=Viola adunca in shade
20040527/05136_erBC Marsh marigold
20040622/05711_erBC Blue-flag iris freak with 6 sepals (the petals look like sepals)
20070522/10686_erC sunset
20070523/10720_erCCCB Purple larkspur=Delphinium nelsonii flower closeup
20070524/10832_erCCB Lance-leaved lungwort=Mertensia lanceolata plant <--new brighter crop
20030610/02595_jn cbc-hunt me+Harebell <--ME-list; undo prev rejection...
--me:
20070629/11445_erC Wood lily flowers <--has replaced Doris's wood-lily: 08497_erCB
20040622/05682_erBC Yellow stargrass=Hypoxis hirsuta at -1.0
20040622/05704_erC Cotton grass in wind
--dragonfly/bee/pronghorn/moose/bison/sheep/goat/caribou/church/barn/Yorkton/St-Joseph/thistle/cact/"the"(town-icon)
20050811/08782_erC Dragonfly
20080705/13578_erCBS Dragonfly mating pair in the mating-wheel position
20030809/04097_erC Bumblebee-red-abdomen=Bombus melanopygus on Tansy
20030821/04290_erC hat-collection on beef farm <--found in /pix/er030822
20070523/10794_erCBS Pronghorn antelope trotting
20060527/09625_erCB Bearberry flowers+foliage (at moose-armpit cave)
20060527/09623_erC British soldiers club-lichens (at moose-armpit cave)
20080711/14112_erC Moose (at Muncho Lake)
20080626/12831_erC Moose skeleton
20080711/14022_erCB Wood bison bull in profile
20080627/12864_erX Mountain goat kid and nanny
20080711/14166_erC Stone sheep
20090704/15774_erC Goatsbeard flower
20080711/14196_erC Caribou male closeup
20030821/04229_erC church at Ste.Genevieve
20040716/06562_erC Bog laurel (Chruchill)
20091018/16659_erCB church in Musee St-Joseph historic-village
20091018/16670_erC barn in Musee St-Joseph historic-village
20070526/10973_erC WDM-Museum 1930 Massey-Harris gasoline tractor
20040713/06195_erC Ball thistle
20080823/14590_erCB Bee two kinds on FlodmansThistle
20030609/02554_er the Inwood snake
20030609/02564_er the Komarno mosquito
20040523/05092_erBCC Blackie supervising
2010-01-09: after these additions, have: 21 FPM*, 135 FPO* (27 per slot);
=> 301,000,000 possible frontpages; clicking reload every second for 10 years...
2010-01-26: not all ME-images are same height??
--use of MAXR=1.0, could lead to some inconsistent height for ME-images??
culprit: