#!/bin/sh
set -eu
mkdir -p static/preview static/thumbnail
resize() {
local photo=$1 size=$2 output=$3
if ! test -f $output; then
# FIXME: convert complains about not understanding XML
echo $output >&2
convert $photo -auto-orient -thumbnail $size $output 2>/dev/null ||:
fi
}
preview() {
local photo=$1
local preview=preview/${photo##*/}
resize $photo 1500000@ static/$preview
echo $preview
}
thumbnail() {
local photo=$1
local thumbnail=thumbnail/${photo##*/}
resize $photo 60000@ static/$thumbnail
echo $thumbnail
}
encode() {
sed '
s/&/\&/g
s/\</g
s/"/\"/g
' "$@"
}
page_title() {
date -j -f '%F' $1 '+%B %e, %Y'
}
page_head() {
local date=$1
local title=$(page_title $date)
local lens film
if test -f $date/lens; then
lens=$(encode $date/lens)
else
lens=$(
identify -format '%[EXIF:LensModel]' \
$date/$(ls -1 $date | head -n 1) 2>/dev/null |
sed '
s/\([A-Z]\)\([0-9]\)/\1 \2/
s,f/,ƒ/,
s/\([0-9]\)-\([0-9]\)/\1–\2/g
' |
encode
)
fi
if test -f $date/film; then
film=$(encode $date/film)
fi
cat <<-EOF
${title}
${title}
📷 ${lens}${film:+ 🎞️ }${film:-}
EOF
}
photo_info() {
local photo=$1
ExposureTime=
FNumber=
FocalLength=
PhotographicSensitivity=
eval $(
identify -format '%[EXIF:*]' $photo 2>/dev/null |
grep -E 'ExposureTime|FNumber|FocalLength|PhotographicSensitivity' |
sed 's/^exif://'
)
}
photo_id() {
local photo=$1
photo=${photo##*/}
photo=${photo%%.*}
echo $photo
}
page_photo() {
local photo=$1 preview=$2 description=$3
if ! test -f $description; then
description=/dev/null
fi
photo_info $photo
cat <<-EOF
EOF
}
index_head() {
cat <<-EOF
Photos
EOF
}
index_page() {
local date=$1 root=${2:-}
cat <<-EOF