#!/bin/sh
#
# THE BEER-WARE LICENSE 2012,13
#
# <as@paefchen.net> wrote this file. As long as you retain this notice you
# 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: scripts/pgallery/src/libpgallery.sh,v 1.6 2013/04/03 08:33:29 as Exp $
#
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"
BIN_JPEGINFO="/usr/local/bin/jpeginfo"
BIN_ICONV="/usr/local/bin/iconv"
ARGFILE=".htpgallery"
VERSION="pgallery-1.4"
#
# get_my_path()
#
get_my_path()
{
current=$(pwd)
cd $(dirname $0)
echo $(pwd)/$(basename $0)
cd "$current"
}
#
# html_header()
#
html_header()
{
cat <<HTML
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$ARG_TITLE</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
background-color: #464646;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFgAAABYB\
AMAAACDuy0HAAAAG1BMVEX+/v4BAQH///8KCgoDAwN/f3/19fWAgID8/PzhDwT2AAAACXRSTlMFBQUFBQU\
FBQWHDtP9AAALwklEQVR4Xg3KOWOyWhAA0Bn2ci57eXEvQY1JCZp8sQTjVoJLTAkaE0swbj/7ve4UB37FL\
W4q86Lwwlh86J/ASAkpWaj+Krbb31HzH0Kjc2tIl7SADaWbpZBPE5dds6jJNyNdjAyKWqdroIixWRQIY6E\
/kOY7hIciL/ZfrAO3XP/06AuUJ3mSd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Vtm5LRaK5KWcD/PX6LaGd25CuN\
HG/vgeIB1kcpCme+J8idlcjfBALAJSggznsGHGOAJgdGduMnZg+bAaeGASGV9bh/X2wPsVTmBLxmTTQsBG\
FkEOkZJTsGAm+HrtMDbWwvTXOutX1u7BxIq9Xib6DkFMbUitNdrYsULkahsAhBEh9FjdzL9BNARxTSr7T3\
u1rE+IWUmCIpwTZHZCu5l9THCuCcOhZqfekuQxjQ7EoyGUJAwCv/q1JOuJeCc/3lknb76zAquO/DAQhK/6\
2cP8X2s3+IBLIhvL8RHopoHpIArJysYTTmMMeubPXh8W760AvMVH67jqgg06+/ne5MZ631z6yROhloh3dP\
QirZoEpr80wgt/cEbhbAQTmRLtGh8lxCwDBBb5OeJ4aEq25XBNMT2rzWedW2zIzj+CCDKlnlyJBzT81qBW\
p69h7vlb3TmEV+DNm2rqj1iT7BQuwVVsuPkwq1e5P8tgNjVbIlMzwXeM11kZqjx3KKFOJzc3CAyFVhi8fx\
VZ5FvhdAM5mM6kS6OgKu16MFglq3/b/QVIwdw7HUCyeW04JPjC5dO+GC9OfqfB4VX+wwuift+ths2Ss3i6\
nkOE+JFyD+wKFL+WMX6nwwDva0S1/O8Mlnida69Ph96fuFvCoRMvXnCfsLPPmC/hA5RnMNE4fDK0pVOQ4B\
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;
width: ${ARG_TNSIZE}px;
vertical-align:text-top;
text-align: center;
margin: 4px;
}
div.t {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
margin-bottom: 1px;
background: rgb(38,38,38); /* Old browsers */
background: -moz-linear-gradient(top, rgba(38,38,38,1) 0%, rgba(53,53,53,1) 50%, rgba(48,48,48,1) 51%, rgba(73,73,73,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(38,38,38,1)), color-stop(50%,rgba(53,53,53,1)), color-stop(51%,rgba(48,48,48,1)), color-stop(100%,rgba(73,73,73,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(38,38,38,1) 0%,rgba(53,53,53,1) 50%,rgba(48,48,48,1) 51%,rgba(73,73,73,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(38,38,38,1) 0%,rgba(53,53,53,1) 50%,rgba(48,48,48,1) 51%,rgba(73,73,73,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(38,38,38,1) 0%,rgba(53,53,53,1) 50%,rgba(48,48,48,1) 51%,rgba(73,73,73,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(38,38,38,1) 0%,rgba(53,53,53,1) 50%,rgba(48,48,48,1) 51%,rgba(73,73,73,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#262626', endColorstr='#494949',GradientType=0 ); /* IE6-9 */
}
div.tn div.t {
width: $(($ARG_TNSIZE - 8))px;
height: 20px;
padding: 0 4px;
line-height: 18px;
}
body > div.t {
font-weight: bold;
position: relative;
bottom: 10px;
padding: 6px;
border-width: 0 0 1px 0;
border-color: gray;
border-style: solid;
box-shadow: 1px 1px 2px #000000;
margin-bottom: -6px;
display: $(test $ARG_NAVI -eq 1 && echo block || echo none);
}
body > div.t div.center {
position: absolute;
text-align: center;
top: 0px;
padding: 6px;
width: 100%;
}
div.tn a {
position: relative;
display: inline-block;
height: ${ARG_TNSIZE}px;
}
div.tn, div.big {
background-color: black;
border-width: 1px;
border-style: solid;
border-color: gray;
box-shadow: 1px 1px 2px #000;
padding: 1px;
border-radius: 3px;
}
div.tn:hover {
background-color: #222;
}
div.big {
display: inline-block;
width: ${ARG_BIGSIZE}px;
}
div.over {
width: ${ARG_BIGSIZE}px;
position: absolute;
top: 30px;
padding: 1px;
}
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;
}
div.over a.left:hover {
background-position: 5% center;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAwC\
AYAAADtoXHnAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAh9JREFUeNrE2L1Lw0A\
UAHATSivSZii0ldpBnMU6SgYJpQUJDlk7dLV+LTqIiIv4B7kLolBKQRA6GLqUDMEhqKAlhUIR4125SHo0b\
XJ51x68pDSX+3G5I/dyguM4S/MuMfeHIAiQ7Yo+//+OocAYPm+jWEXxg8JC8erCgvt4AXrqgkkUJRRZ6jq\
G71EMRcAeil6wWq2uGYZx1ul0jjRNy5Jey6PauKcRJ5NIhklCoaE4QODNYDCwHVJ6vd5HIpE4xNdQxKOiM\
0G3FIvFc4Imo6CBQV3XXwioje5jREOBkiQdE3SLFWUFFXJfaJQVLP2DIWdvFDA+9pYKiMKBAVFYMAAKD85\
A+YBTUH6gD8oXnIDyB31QviCFzgekUPxYVe4ghW7ixhRFueQKUmgZN9hut1s0aNv2V6FQOAUBqRvT+IAaX\
6crWZb1hsqQJFfPkPnpJz6YpmnQlXK5XD6TycRIcrUDib7jQ71ev+v3+9/eSqlUKt1qtU4IvIFid2x9jDC\
muJE9PG6qql7jcaTHttvt6gh2J1MZYva6ees+d9jnjcQXnoDyh31WGb7wlPWUHzwjc+ADB8iR4OGA2SAsH\
CLvhYNDZvgwMMO3THSY8auNBS6xfrVFhZUoaGjYk+qA7DkEgmu12i1Bs1C7K1NhvLviecTLEOhEuFKpXDW\
bzcdGo/Egy/KFZzKJPHbMVsiEyVPXTRRPeMdMWMQuqLi0gPInwACOBcZx3lRFMwAAAABJRU5ErkJggg==");
}
div.over a.right:hover {
background-position: 95% center;
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAwC\
AYAAADtoXHnAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAiJJREFUeNrE2D1Lw0A\
YAOAmlNbBdii0FVM6OEu7SgcJpRUJDlk7dE21uuggIi7iD/IX+AGlFAXBDqVLyVCCBBW0JFhwMN7JHRxnY\
5PcnX3hhSM58nB3+Xhzkud5sf8OiWjLPn2+eGF4gHEChLkOcgUdt0E+isAlhCVAbiGQjGeQ1yBdHjAeKZ7\
SCgR1Xc8Nh8M90zQPG42GAo7lQFZBLhOzwSXgKI1kMrk7mUxePBTT6dQB8Dk8B1IHmUbTLrOMFI8WjsIol\
8tHHhW8YRKV0QWNwWDwIBKm0RK8aDqdbouEaRReQBUNkygJV0XCNBojnldh8CxUOOyHCoX/QoXB81AhcBC\
UOxwU5QqHQbnBYVFWODLKDEdFo8IanGYWNBSsquoJgkus6C+4UCgcOI7zRsP9fv8OoTWM8qh57mHlaFnWp\
23bFn1SUZQiambm1bphYgMWddlsNp7P51fpk+Px2ETNV1YUf383Qa5BsNfr7adSqQzZyXXd91ardUmUs8x\
rWYNrBcD2aDQa0GsJ11fTtDO0ntssd28UcAfXzSxvpLBg5DcSKyhH/cowgVG+p8xg2MqBCximRuIGBq0Gu\
YJB6l7u4LwKXwjo9y8jFPT7a6uKBGehqmiQRhO45BAJ0ijcQTGazeaFSJBGl/DUkrsrvMFZa/pzE1UqleN\
Op3PV7XZv6vX6KU+QRMkdM3gzFal+TyBvQX7w3DGTFrELKscWEN8CDADBm8pgcciwqgAAAABJRU5ErkJgg\
g==");
}
div.big a {
position: relative;
display: inline-block;
width: ${ARG_BIGSIZE}px;
}
div.box {
text-align: center;
width: ${ARG_BIGSIZE}px;
margin: auto;
}
div.box div.d {
width: ${ARG_BIGSIZE}px;
padding: 5px;
text-align: center;
}
div.box div.i {
width: ${ARG_BIGSIZE}px;
font-size: 90%;
height: 25px;
line-height: 25px;
position: relative;
}
body > div.c {
text-align: center;
font-size: 90%;
height: 25px;
line-height: 25px;
position: relative;
margin: 4px;
}
a img {
border-width: 0;
}
a {
}
div.nav {
width: ${ARG_BIGSIZE}px;
height: 20px;
}
a {
color: #FFF;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
div.nav div.top {
position: absolute;
text-align: center;
width: $(($ARG_BIGSIZE - 100))px;
margin: 0 50px;
}
.left {
float: left;
}
.right {
float: right;
}
.clear {
clear: both;
}
-->
</style>
</head>
<body>
HTML
}
#
# html_footer()
#
html_footer()
{
cat <<HTML
</body></html>
HTML
}
#
# html_tn()
#
html_tn()
{
tn=$1
link=$2
title="$3"
info=$($BIN_IMGINFO -f $tn)
width=$(echo $info | awk '{print $3}')
height=$(echo $info | awk '{print $4}')
top=$(($(($ARG_TNSIZE - $height)) / 2))
test "$title" != "" && title="<div class='t'>$title</div>"
cat <<HTML
<div class="tn">
$title
<a href="$link" style="top:${top}px">
<img alt="$tn" width="$width" height="$height" src="$tn" />
</a>
</div>
HTML
}
#
# html_img()
#
html_img()
{
orig=$1
num=$2
all=$3
img=$4
link=$5
linkb=$6
linkn=$7
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="<div class='d'>$desc</div>"
fi
if [ "$linkb" != "" ]
then
hlinkb="<a href='$linkb'>prev</a>"
olinkb="<a class='left' style='height:${height}px' href='$linkb'></a>"
fi
if [ "$linkn" != "" ]
then
hlinkn="<a href="$linkn">next</a>"
olinkn="<a class='right' style='height:${height}px' href='$linkn'></a>"
fi
cat <<HTML
<div class="box">
<div class="nav">
<div class="top">
<a href="$link">index</a> | <a href="$orig">original</a> | $num/$all
</div>
<div class="left">$hlinkb</div>
<div class="right">$hlinkn</div>
</div>
<div class="big">
<img alt="$img" width="$width" height="$height" src="$img" />
</div>
$desc
<div class="i">
<div class="left">$(get_exif_info $orig)</div>
<div class="right">$ARG_TITLE $ARG_COPYRIGHT</div>
</div>
<div class="over" style='height:${height}px'>
$olinkb
$olinkn
</div>
</div>
HTML
}
#
# html_title()
#
html_title()
{
left="$1"
center="$2"
right="$3"
cat <<HTML
<div class="t">
<div class="left">$left</div>
<div class="right">$right</div>
<div class="center">$center</div>
<div class="clear"></div>
</div>
HTML
}
#
# err
#
err()
{
echo "$1" >&2
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 | 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)
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/( |([[:digit:]]))se(c|k)\./\2s/' -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
}