version 1.4, 2012/08/28 08:43:05
|
version 1.12, 2012/08/29 12:30:35
|
Line 5
|
Line 5
|
# can do whatever you want with this stuff. If we meet some day, and you think |
# 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 |
# this stuff is worth it, you can buy me a beer in return Aron Schlesinger |
# |
# |
# $Paefchen: scripts/pgallery/src/pgallery.sh,v 1.3 2012/08/28 08:27:25 as Exp $ | # $Paefchen: scripts/pgallery/src/pgallery.sh,v 1.11 2012/08/29 11:21:41 as Exp $ |
# |
# |
|
|
ARG_TITLE="PGallery" |
ARG_TITLE="PGallery" |
Line 19 ARG_INDEX="index.html"
|
Line 19 ARG_INDEX="index.html"
|
ARG_DIR="." |
ARG_DIR="." |
ARG_UPDATE=1 |
ARG_UPDATE=1 |
ARG_COPYRIGHT="© $(date +%Y)" |
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_CONVERT="/usr/local/bin/convert" |
BIN_EXIFAUTOTRAN="/usr/local/bin/exifautotran" |
BIN_EXIFAUTOTRAN="/usr/local/bin/exifautotran" |
BIN_IMGINFO="/usr/local/bin/imginfo" |
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" |
MKAKEFILE=".htmakefile" |
VERSION="pgallery-1" | VERSION="pgallery-1.2" |
|
|
# |
# |
# usage() |
# usage() |
Line 35 usage()
|
Line 43 usage()
|
cat <<USAGE |
cat <<USAGE |
usage $0: ( [-f <files>] | [-s <suffix>] ) [-d <dir>] [-n <name>] |
usage $0: ( [-f <files>] | [-s <suffix>] ) [-d <dir>] [-n <name>] |
[-t <thumbnail_size>] [-u <thumbnail_quality>] |
[-t <thumbnail_size>] [-u <thumbnail_quality>] |
[-b <big_size>] [-c <big_quality>] | [-b <big_size>] [-c <big_quality>] [-l link] [-e <exif>] |
[-i <index>] [-C <copyright>] [-U] | -h | -v | [-i <index>] [-C <copyright>] [-F <mailfrom>] [-T <mailto>] |
| [-U] | -h | -v |
Options: |
Options: |
-b size size from big images in pixel (default: $ARG_BIGSIZE) |
-b size size from big images in pixel (default: $ARG_BIGSIZE) |
-c quality quality from big images 0-100% (default: $ARG_BIGQALITY) |
-c quality quality from big images 0-100% (default: $ARG_BIGQALITY) |
-d dir gallery dir (default: $ARG_DIR) |
-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 |
-f files gallery images |
-h this page |
-h this page |
-i name index file name (default: $ARG_INDEX) |
-i name index file name (default: $ARG_INDEX) |
|
-l url gallery link |
-n name page title (default: $ARG_TITLE) |
-n name page title (default: $ARG_TITLE) |
-s suffix list of suffix. if no \`\`-f'' defined, used to find images |
-s suffix list of suffix. if no \`\`-f'' defined, used to find images |
in \`\`-d'' directoy. case insensitive |
in \`\`-d'' directoy. case insensitive |
Line 52 Options:
|
Line 64 Options:
|
-u quality quality from thumbnail images 0-100% (default: $ARG_BIGQALITY) |
-u quality quality from thumbnail images 0-100% (default: $ARG_BIGQALITY) |
-v print version |
-v print version |
-C copyright copyright (html) string (default: $ARG_COPYRIGHT) |
-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. |
-U no update, new calculation of all images. |
normally only new and modified images will calculated |
normally only new and modified images will calculated |
USAGE |
USAGE |
Line 141 HLaErzv/wD99ABmjNZk0AAAAABJRU5ErkJggg==");
|
Line 160 HLaErzv/wD99ABmjNZk0AAAAABJRU5ErkJggg==");
|
font-family: Geneva,Arial,sans-serif; |
font-family: Geneva,Arial,sans-serif; |
font-size: 12px; |
font-size: 12px; |
text-shadow: 1px 1px 1px #000; |
text-shadow: 1px 1px 1px #000; |
|
color: #808080; |
} |
} |
div.tn { |
div.tn { |
float: left; |
float: left; |
Line 225 div.box {
|
Line 245 div.box {
|
width: ${ARG_BIGSIZE}px; |
width: ${ARG_BIGSIZE}px; |
margin: auto; |
margin: auto; |
} |
} |
div.box div.c { | div.box div.d { |
width: ${ARG_BIGSIZE}px; |
width: ${ARG_BIGSIZE}px; |
text-align: right; | padding: 5px; |
| text-align: center; |
| } |
| div.box div.i { |
| width: ${ARG_BIGSIZE}px; |
font-size: 90%; |
font-size: 90%; |
color: #808080; |
|
height: 25px; |
height: 25px; |
line-height: 25px; |
line-height: 25px; |
position: relative; |
position: relative; |
left: 4px; |
|
} |
} |
body > div.c { |
body > div.c { |
text-align: center; |
text-align: center; |
font-size: 90%; |
font-size: 90%; |
color: #808080; |
|
height: 25px; |
height: 25px; |
line-height: 25px; |
line-height: 25px; |
position: relative; |
position: relative; |
Line 319 HTML
|
Line 340 HTML
|
# |
# |
html_img() |
html_img() |
{ |
{ |
img=$1 | orig=$1 |
link=$2 | num=$2 |
linkb=$3 | all=$3 |
linkn=$4 | img=$4 |
| link=$5 |
| linkb=$6 |
| linkn=$7 |
|
|
info=$($BIN_IMGINFO -f $img) |
info=$($BIN_IMGINFO -f $img) |
width=$(echo $info | awk '{print $3}') |
width=$(echo $info | awk '{print $3}') |
height=$(echo $info | awk '{print $4}') |
height=$(echo $info | awk '{print $4}') |
|
|
|
desc=$(get_exif_desc $orig) |
|
if [ "$desc" != "" ] |
|
then |
|
desc="<div class='d'>$desc</div>" |
|
fi |
|
|
if [ "$linkb" != "" ] |
if [ "$linkb" != "" ] |
then |
then |
hlinkb="<a href='$linkb'>zurück</a>" | hlinkb="<a href='$linkb'>back</a>" |
olinkb="<a class='left' style='height:${height}px' href='$linkb'></a>" |
olinkb="<a class='left' style='height:${height}px' href='$linkb'></a>" |
fi |
fi |
|
|
if [ "$linkn" != "" ] |
if [ "$linkn" != "" ] |
then |
then |
hlinkn="<a href="$linkn">weiter</a>" | hlinkn="<a href="$linkn">forward</a>" |
olinkn="<a class='right' style='height:${height}px' href='$linkn'></a>" |
olinkn="<a class='right' style='height:${height}px' href='$linkn'></a>" |
fi |
fi |
|
|
cat <<HTML |
cat <<HTML |
<div class="box"> |
<div class="box"> |
<div class="nav"> |
<div class="nav"> |
<div class="top"><a href="$link">Index</a></div> | <div class="top"> |
| <a href="$link">Index</a> | <a href="$orig">original</a> | $num/$all |
| </div> |
<div class="left">$hlinkb</div> |
<div class="left">$hlinkb</div> |
<div class="right">$hlinkn</div> |
<div class="right">$hlinkn</div> |
</div> |
</div> |
<div class="big"> |
<div class="big"> |
<img alt="$img" width="$width" height="$height" src="$img" /> |
<img alt="$img" width="$width" height="$height" src="$img" /> |
</div> |
</div> |
<div class="c"> | $desc |
$ARG_TITLE $ARG_COPYRIGHT | <div class="i"> |
| <div class="left">$(get_exif_info $orig)</div> |
| <div class="right">$ARG_TITLE $ARG_COPYRIGHT</div> |
</div> |
</div> |
<div class="over" style='height:${height}px'> |
<div class="over" style='height:${height}px'> |
$olinkb |
$olinkb |
Line 370 err()
|
Line 404 err()
|
exit 1 |
exit 1 |
} |
} |
|
|
|
# |
|
# mysendmail() |
|
# |
|
mysendmail() |
|
{ |
|
subject=$1 |
|
( |
|
cat <<MAIL |
|
From: $ARG_MAILFROM |
|
To: $ARG_MAILTO |
|
Subject: $subject |
|
Content-Type: text/plain; charset=iso-8859-1 |
|
X-Mailer: $VERSION |
|
|
|
$(cat) |
|
MAIL |
|
) | $BIN_SENDMAIL -t |
|
} |
|
|
|
# |
|
# get_exif_desc() |
|
# |
|
get_exif_desc() |
|
{ |
|
img=$1 |
|
$BIN_EXIF --ifd=0 --tag=0x010e -m $img 2> /dev/null | iconv -t ISO-8859-1 -f UTF-8 | while read line |
|
do |
|
echo "$line<br />" |
|
done |
|
} |
|
|
|
# |
|
# get_exif_ts() |
|
# |
|
get_exif_ts() |
|
{ |
|
img=$1 |
|
date=$($BIN_EXIF --ifd=EXIF --tag=0x9003 -m $img 2> /dev/null) |
|
test "$date" = "" && return 1 |
|
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 |
# parse args |
while [ "$1" != "" ] |
while [ "$1" != "" ] |
do |
do |
Line 378 do
|
Line 508 do
|
shift |
shift |
case $arg in |
case $arg in |
-h) |
-h) |
usage | usage;; |
;; | |
-n) |
-n) |
ARG_TITLE=$1 |
ARG_TITLE=$1 |
shift | shift;; |
;; | |
-t) |
-t) |
ARG_TNSIZE=$1 |
ARG_TNSIZE=$1 |
shift | shift;; |
;; | |
-u) |
-u) |
ARG_TNQALITY=$1 |
ARG_TNQALITY=$1 |
shift | shift;; |
;; | |
-b) |
-b) |
ARG_BIGSIZE=$1 |
ARG_BIGSIZE=$1 |
shift | shift;; |
;; | |
-c) |
-c) |
ARG_BIGQALITY=$1 |
ARG_BIGQALITY=$1 |
shift | shift;; |
;; | |
-f) |
-f) |
ARG_FILES=$1 |
ARG_FILES=$1 |
shift | shift;; |
;; | -l) |
| ARG_URL=$1 |
| shift;; |
-s) |
-s) |
ARG_FILETYPES=$1 |
ARG_FILETYPES=$1 |
shift | shift;; |
;; | |
-d) |
-d) |
ARG_DIR=$1 |
ARG_DIR=$1 |
shift | shift;; |
;; | -e) |
| ARG_EXIF=$1 |
| shift;; |
-C) |
-C) |
ARG_COPYRIGHT=$1 |
ARG_COPYRIGHT=$1 |
shift | shift;; |
;; | -F) |
| ARG_MAILFROM=$1 |
| shift;; |
| -I) |
| ARG_INFOFILE=$1 |
| shift;; |
| -T) |
| ARG_MAILTO=$1 |
| shift;; |
-U) |
-U) |
ARG_UPDATE=0 | ARG_UPDATE=0;; |
;; | |
-v) |
-v) |
echo $VERSION |
echo $VERSION |
exit | exit;; |
;; | |
*) |
*) |
echo "unknown argument $arg" |
echo "unknown argument $arg" |
exit |
exit |
esac |
esac |
done |
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) |
MY=$(get_my_path) |
cd "$ARG_DIR" || exit 1 |
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 no images defined, find files |
if [ "$ARG_FILES" = "" -a "$ARG_FILETYPES" != "" ] |
if [ "$ARG_FILES" = "" -a "$ARG_FILETYPES" != "" ] |
then |
then |
Line 457 echo
|
Line 610 echo
|
|
|
test $(echo $FLIST | wc -w) -eq 0 && err "error: no image found in \`\`$ARG_DIR''" |
test $(echo $FLIST | wc -w) -eq 0 && err "error: no image found in \`\`$ARG_DIR''" |
|
|
|
# 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 <<MAKE |
|
$tn: $file |
|
@echo ${file} |
|
MAKE |
|
) >> $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. |
# Create make file to rotate und convert all big and thumbnails. |
# Is needed to define the new real image sizes. |
# Is needed to define the new real image sizes. |
echo "all: tns" > $MKAKEFILE |
echo "all: tns" > $MKAKEFILE |
Line 476 do
|
Line 668 do
|
fi |
fi |
|
|
( |
( |
cat <<MAKE | cat <<MAKE |
$target |
$target |
$BIN_EXIFAUTOTRAN $file |
$BIN_EXIFAUTOTRAN $file |
$BIN_CONVERT -verbose -thumbnail ${ARG_TNSIZE}x${ARG_TNSIZE} -quality $ARG_TNQALITY $file $tn |
$BIN_CONVERT -verbose -thumbnail ${ARG_TNSIZE}x${ARG_TNSIZE} -quality $ARG_TNQALITY $file $tn |
Line 486 MAKE
|
Line 678 MAKE
|
done |
done |
echo "tns: $targets" >> $MKAKEFILE |
echo "tns: $targets" >> $MKAKEFILE |
|
|
make -f $MKAKEFILE | #make -f $MKAKEFILE |
rm $MKAKEFILE |
rm $MKAKEFILE |
|
|
# create single html files | # create html index |
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 "<div class='clear'></div>" |
|
echo "<div class='c'>$ARG_TITLE $ARG_COPYRIGHT</div>" |
|
html_footer |
|
) > $ARG_INDEX |
|
|
|
# create single html files |
|
#test $ARG_UPDATE -eq 1 && FLIST="$FLIST_NEW $FLIST_UPDATE" |
i=0 |
i=0 |
|
all=$(echo $FLIST | wc -w) |
echo -n "create single html files " |
echo -n "create single html files " |
for file in $FLIST |
for file in $FLIST |
do |
do |
Line 499 do
|
Line 709 do
|
i=$(($i + 1)) |
i=$(($i + 1)) |
j=$(($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" |
big="${file}.big.jpg" |
imglink="${file}.html" |
imglink="${file}.html" |
|
|
Line 511 do
|
Line 726 do
|
test "$linkn" != "" && linkn="$linkn.html" |
test "$linkn" != "" && linkn="$linkn.html" |
|
|
echo -n . |
echo -n . |
index="$index $(html_tn $tn $imglink)" |
|
( |
( |
html_header |
html_header |
html_img $big $ARG_INDEX "$linkb" "$linkn" | html_img $file $i $all $big $ARG_INDEX "$linkb" "$linkn" |
html_footer |
html_footer |
) > $imglink |
) > $imglink |
done |
done |
echo |
echo |
|
|
# create html index | test "$ARG_MAILTO" = "" && exit 0 |
echo create html index | |
( | # send info mail |
html_header | if [ "$FLIST_NEW" != "" -o "$FLIST_UPDATE" != "" ] |
echo $index | then |
echo "<div class='clear'></div>" | echo "send mail to $ARG_MAILTO" |
echo "<div class='c'>$ARG_TITLE $ARG_COPYRIGHT</div>" | ( |
html_footer | echo "Hallo," |
) > $ARG_INDEX | 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 |