--- scripts/pgallery/src/pgallery.sh 2012/08/27 14:23:59 1.1 +++ scripts/pgallery/src/pgallery.sh 2012/08/29 12:41:06 1.13 @@ -5,7 +5,7 @@ # can do whatever you want with this stuff. If we meet some day, and you think # this stuff is worth it, you can buy me a beer in return Aron Schlesinger # -# $Paefchen$ +# $Paefchen: scripts/pgallery/src/pgallery.sh,v 1.12 2012/08/29 12:30:35 as Exp $ # ARG_TITLE="PGallery" @@ -19,13 +19,21 @@ ARG_INDEX="index.html" ARG_DIR="." ARG_UPDATE=1 ARG_COPYRIGHT="© $(date +%Y)" +ARG_INFOFILE="" +ARG_MAILTO="" +ARG_MAILFROM="PGallery <${USER}@${HOST}>" +ARG_URL= +ARG_EXIF="0x920a 0x829d 0x829a ISO 0x8827 / 0x010f - 0x0110" BIN_CONVERT="/usr/local/bin/convert" BIN_EXIFAUTOTRAN="/usr/local/bin/exifautotran" BIN_IMGINFO="/usr/local/bin/imginfo" +BIN_SENDMAIL="/usr/sbin/sendmail" +BIN_EXIFTRAN="/usr/local/bin/exiftran" +BIN_EXIF="/usr/local/bin/exif" MKAKEFILE=".htmakefile" -VERSION="pgallery-1" +VERSION="pgallery-1.2" # # usage() @@ -35,25 +43,36 @@ usage() cat <] | [-s ] ) [-d ] [-n ] [-t ] [-u ] - [-b ] [-c ] - [-i ] [-U] | -h + [-b ] [-c ] [-l link] [-e ] + [-i ] [-C ] [-F ] [-T ] + [-U] | -h | -v Options: -b size size from big images in pixel (default: $ARG_BIGSIZE) -c quality quality from big images 0-100% (default: $ARG_BIGQALITY) -d dir gallery dir (default: $ARG_DIR) + -e exif list of tags in hex. (default: $ARG_EXIF) + see: http://www.exiv2.org/tags.html -f files gallery images -h this page -i name index file name (default: $ARG_INDEX) + -l url gallery link -n name page title (default: $ARG_TITLE) -s suffix list of suffix. if no \`\`-f'' defined, used to find images in \`\`-d'' directoy. case insensitive (default: $ARG_FILETYPES) -t size size from thumbnail images in pixel (default: $ARG_TNSIZE) -u quality quality from thumbnail images 0-100% (default: $ARG_BIGQALITY) + -v print version + -C copyright copyright (html) string (default: $ARG_COPYRIGHT) + -F from mail sender (default: $ARG_MAILFROM) + -I file info text file for pgallery. info file paras prefered. + the syntax of the file is MAKE(1) + supported variable: TITLE COPYRIGHT INDEX FILETYPES TNSIZE URL + TNQALITY BIGSIZE BIGQALITY MAILTO MAILFROM + EXIF + -T mailto send update infos to this address. if not set, no mail delivery -U no update, new calculation of all images. normally only new and modified images will calculated - -C copyright copyright (html) string (default: $ARG_COPYRIGHT) - -v print version USAGE exit } @@ -140,6 +159,8 @@ HLaErzv/wD99ABmjNZk0AAAAABJRU5ErkJggg=="); margin: 10px auto; font-family: Geneva,Arial,sans-serif; font-size: 12px; + text-shadow: 1px 1px 1px #000; + color: #808080; } div.tn { float: left; @@ -161,6 +182,7 @@ div.tn, div.big { border-color: gray; box-shadow: 1px 1px 2px #000; padding: 1px; + border-radius: 3px; } div.tn:hover { background-color: #222; @@ -177,11 +199,12 @@ div.over { } div.over a.left, div.over a.right { display: block; + /* shell fuck of: missing CTLARI (shouldn't happen) - WTF?! */ + width: $(($ARG_BIGSIZE / 2))px; position: relative; top: 1px; left: 1px; background-repeat: no-repeat; - width: $(($ARG_BIGSIZE / 2))px; } div.over a.left:hover { background-position: 5% center; @@ -222,25 +245,24 @@ div.box { width: ${ARG_BIGSIZE}px; margin: auto; } -div.box div.c { +div.box div.d { width: ${ARG_BIGSIZE}px; - text-align: right; + padding: 5px; + text-align: center; +} +div.box div.i { + width: ${ARG_BIGSIZE}px; font-size: 90%; - color: #808080; height: 25px; line-height: 25px; position: relative; - left: 4px; - text-shadow: 1px 1px 1px #000; } body > div.c { text-align: center; font-size: 90%; - color: #808080; height: 25px; line-height: 25px; position: relative; - text-shadow: 1px 1px 1px #000; margin: 4px; } a img { @@ -262,7 +284,8 @@ div.nav a:hover { div.nav div.top { position: absolute; text-align: center; - width: ${ARG_BIGSIZE}px; + width: $(($ARG_BIGSIZE - 100))px; + margin: 0 50px; } .left { float: left; @@ -317,37 +340,52 @@ HTML # html_img() { - img=$1 - link=$2 - linkb=$3 - linkn=$4 + orig=$1 + num=$2 + all=$3 + img=$4 + link=$5 + linkb=$6 + linkn=$7 - height=$($BIN_IMGINFO -f $img | awk '{print $4}') + info=$($BIN_IMGINFO -f $img) + width=$(echo $info | awk '{print $3}') + height=$(echo $info | awk '{print $4}') + desc=$(get_exif_desc $orig) + if [ "$desc" != "" ] + then + desc="
$desc
" + fi + if [ "$linkb" != "" ] then - hlinkb="zurück" + hlinkb="back" olinkb="" fi if [ "$linkn" != "" ] then - hlinkn="weiter" + hlinkn="forward" olinkn="" fi cat <
- + $img
-
- $ARG_TITLE $ARG_COPYRIGHT + $desc +
+
$(get_exif_info $orig)
+
$ARG_TITLE $ARG_COPYRIGHT
$olinkb @@ -366,7 +404,107 @@ err() exit 1 } +# +# mysendmail() +# +mysendmail() +{ + subject=$1 + ( + cat < /dev/null | iconv -t ISO-8859-1 -f UTF-8 | while read line + do + echo "$line
" + done +} + +# +# get_exif_ts() +# +get_exif_ts() +{ + img=$1 + date=$($BIN_EXIF --ifd=EXIF --tag=0x9003 -m $img 2> /dev/null) + if [ "$date" = "" ] + then + echo "-1" + return 1 + fi + date -j -f "%Y:%m:%d %T" "$date" "+%s" +} + +# +# get_exif_date() +# +get_exif_date() +{ + img=$1 + ts=$(get_exif_ts $img) && date -r $ts "+%d.%m.%Y %H:%M" || echo "" +} + +# +# get_exif_value() +# +get_exif_value() +{ + img=$1 + hex=$2 + $BIN_EXIFTRAN -d $img | grep $hex | sed -E 's/^.{45}//' +} + +# +# get_exif_info() +# +get_exif_info() +{ + img=$1 + + exifinfo= + created=$(get_exif_date $img) && exifinfo="$created / " + + for exif in $ARG_EXIF + do + if echo $exif | grep -q -E '0x[[:alnum:]]{4}' + then + exifinfo="$exifinfo$(get_exif_value $img $exif) " + else + exifinfo="$exifinfo$exif " + fi + done + echo $exifinfo | sed -E -e 's/ mm /mm /' -e 's/ sec./s/' -e 's/ ISO / ISO/' -e 's/ ISO(\/| )/ \1/' +} + +# +# is_in_list() +# +is_in_list() +{ + list=$1 + value=$2 + for entry in $list + do + test "$entry" = "$value" && return 0 + done + return 1 +} + # parse args while [ "$1" != "" ] do @@ -374,60 +512,83 @@ do shift case $arg in -h) - usage - ;; + usage;; -n) ARG_TITLE=$1 - shift - ;; + shift;; -t) ARG_TNSIZE=$1 - shift - ;; + shift;; -u) ARG_TNQALITY=$1 - shift - ;; + shift;; -b) ARG_BIGSIZE=$1 - shift - ;; + shift;; -c) ARG_BIGQALITY=$1 - shift - ;; + shift;; -f) ARG_FILES=$1 - shift - ;; + shift;; + -l) + ARG_URL=$1 + shift;; -s) ARG_FILETYPES=$1 - shift - ;; + shift;; -d) ARG_DIR=$1 - shift - ;; + shift;; + -e) + ARG_EXIF=$1 + shift;; -C) ARG_COPYRIGHT=$1 - shift - ;; + shift;; + -F) + ARG_MAILFROM=$1 + shift;; + -I) + ARG_INFOFILE=$1 + shift;; + -T) + ARG_MAILTO=$1 + shift;; -U) - ARG_UPDATE=0 - ;; + ARG_UPDATE=0;; -v) echo $VERSION - exit - ;; + exit;; *) echo "unknown argument $arg" exit esac done +# parese info file +if [ "$ARG_INFOFILE" != "" ] +then + test -f $ARG_INFOFILE || err "info file not found \`\`$ARG_INFOFILE''" + for n in TITLE COPYRIGHT INDEX FILETYPES TNSIZE TNQALITY BIGSIZE \ + BIGQALITY MAILTO MAILFROM URL EXIF + do + v=$(make -f $ARG_INFOFILE -V$n) + test "$v" = "" && continue + eval "ARG_$n='$v'" + done +fi + +# go to gallery directory MY=$(get_my_path) cd "$ARG_DIR" || exit 1 +# fix url +if [ "$ARG_URL" != "" ] +then + echo "$ARG_URL" | grep -q '/$' || ARG_URL="${ARG_URL}/" +fi + # if no images defined, find files if [ "$ARG_FILES" = "" -a "$ARG_FILETYPES" != "" ] then @@ -453,6 +614,55 @@ echo test $(echo $FLIST | wc -w) -eq 0 && err "error: no image found in \`\`$ARG_DIR''" +# use exif createtime to order images +FLIST=$( + ( + for file in $FLIST + do + echo "$(get_exif_ts $file) $file" + done + ) | sort -n | awk '{print $2}' +) + +# find new and to update images +FLIST_NEW= +FLIST_UPDATE= +echo "all: tns" > $MKAKEFILE +targets="" +for file in $FLIST +do + tn="${file}.tn.jpg" + if [ ! -f $tn ] + then + FLIST_NEW="$FLIST_NEW $file" + continue + fi + + targets="$targets $tn" + ( + cat <> $MKAKEFILE +done +echo "tns: $targets" >> $MKAKEFILE +FLIST_UPDATE=$(make -f $MKAKEFILE) +rm $MKAKEFILE + +# update and no new and update images found +if [ $ARG_UPDATE -eq 1 -a "$FLIST_NEW" = "" -a "$FLIST_UPDATE" = "" ] +then + echo nothing to do + exit 1 +fi + +if [ $ARG_UPDATE -eq 1 ] +then + echo new images: $FLIST_NEW + echo update images: $FLIST_UPDATE +fi + # Create make file to rotate und convert all big and thumbnails. # Is needed to define the new real image sizes. echo "all: tns" > $MKAKEFILE @@ -472,7 +682,7 @@ do fi ( - cat <> $MKAKEFILE -make -f $MKAKEFILE +#make -f $MKAKEFILE rm $MKAKEFILE -# create single html files +# create html index index="" +for file in $FLIST +do + tn="${file}.tn.jpg" + imglink="${file}.html" + index="$index $(html_tn $tn $imglink)" +done +echo create html index +( + html_header + echo $index + echo "
" + echo "
$ARG_TITLE $ARG_COPYRIGHT
" + html_footer +) > $ARG_INDEX + +# create single html files +#test $ARG_UPDATE -eq 1 && FLIST="$FLIST_NEW $FLIST_UPDATE" i=0 +all=$(echo $FLIST | wc -w) echo -n "create single html files " for file in $FLIST do @@ -495,7 +723,12 @@ do i=$(($i + 1)) j=$(($i + 1)) - tn="${file}.tn.jpg" + # is update mod and no new images founded + if [ $ARG_UPDATE -eq 1 -a "$FLIST_NEW" = "" ] + then + is_in_list "$FLIST_UPDATE" "$file" || continue + fi + big="${file}.big.jpg" imglink="${file}.html" @@ -507,21 +740,53 @@ do test "$linkn" != "" && linkn="$linkn.html" echo -n . - index="$index $(html_tn $tn $imglink)" ( html_header - html_img $big $ARG_INDEX "$linkb" "$linkn" + html_img $file $i $all $big $ARG_INDEX "$linkb" "$linkn" html_footer ) > $imglink done echo -# create html index -echo create html index -( - html_header - echo $index - echo "
" - echo "
$ARG_TITLE $ARG_COPYRIGHT
" - html_footer -) > $ARG_INDEX +test "$ARG_MAILTO" = "" && exit 0 + +# send info mail +if [ "$FLIST_NEW" != "" -o "$FLIST_UPDATE" != "" ] +then + echo "send mail to $ARG_MAILTO" + ( + echo "Hallo," + echo + echo -n "the gallery $ARG_TITLE has been updated" + if [ "$ARG_URL" != "" ] + then + echo ":" + echo $ARG_URL + else + echo "." + fi + + suffix= + test "$ARG_URL" != "" && suffix=.html + + if [ "$FLIST_NEW" != "" ] + then + echo + echo "add pictures:" + for file in $FLIST_NEW + do + echo "- ${ARG_URL}${file}${suffix}" + done + fi + + if [ "$FLIST_UPDATE" != "" ] + then + echo + echo "update pictures:" + for file in $FLIST_UPDATE + do + echo "- ${ARG_URL}${file}${suffix}" + done + fi + ) | mysendmail "PGallery Update: $ARG_TITLE" +fi