Annotation of scripts/pgallery/src/pgallery.sh, revision 1.13

1.1       as          1: #!/bin/sh
                      2: #
                      3: # THE BEER-WARE LICENSE 2012
                      4: # <as@paefchen.net> wrote this file. As long as you retain this notice you
                      5: # can do whatever you want with this stuff. If we meet some day, and you think
                      6: # this stuff is worth it, you can buy me a beer in return Aron Schlesinger
                      7: #
1.13    ! as          8: # $Paefchen: scripts/pgallery/src/pgallery.sh,v 1.12 2012/08/29 12:30:35 as Exp $
1.1       as          9: #
                     10: 
                     11: ARG_TITLE="PGallery"
                     12: ARG_FILES=
                     13: ARG_FILETYPES="jpg jpeg png gif tif tiff"
                     14: ARG_TNSIZE="180"
                     15: ARG_TNQALITY="70"
                     16: ARG_BIGSIZE="950"
                     17: ARG_BIGQALITY="90"
                     18: ARG_INDEX="index.html"
                     19: ARG_DIR="."
                     20: ARG_UPDATE=1
                     21: ARG_COPYRIGHT="&copy; $(date +%Y)"
1.6       as         22: ARG_INFOFILE=""
                     23: ARG_MAILTO=""
                     24: ARG_MAILFROM="PGallery <${USER}@${HOST}>"
                     25: ARG_URL=
1.7       as         26: ARG_EXIF="0x920a 0x829d 0x829a ISO 0x8827 / 0x010f - 0x0110"
1.1       as         27: 
                     28: BIN_CONVERT="/usr/local/bin/convert"
                     29: BIN_EXIFAUTOTRAN="/usr/local/bin/exifautotran"
                     30: BIN_IMGINFO="/usr/local/bin/imginfo"
1.6       as         31: BIN_SENDMAIL="/usr/sbin/sendmail"
1.7       as         32: BIN_EXIFTRAN="/usr/local/bin/exiftran"
                     33: BIN_EXIF="/usr/local/bin/exif"
1.1       as         34: 
                     35: MKAKEFILE=".htmakefile"
1.9       as         36: VERSION="pgallery-1.2"
1.1       as         37: 
                     38: #
                     39: # usage()
                     40: #
                     41: usage()
                     42: {
                     43:        cat <<USAGE
                     44: usage $0: ( [-f <files>] | [-s <suffix>] ) [-d <dir>] [-n <name>]
                     45:                 [-t <thumbnail_size>] [-u <thumbnail_quality>]
1.7       as         46:                 [-b <big_size>] [-c <big_quality>] [-l link] [-e <exif>]
1.6       as         47:                 [-i <index>] [-C <copyright>] [-F <mailfrom>] [-T <mailto>]
                     48:                 [-U] | -h | -v
1.1       as         49: Options:
                     50:   -b size       size from big images in pixel (default: $ARG_BIGSIZE)
                     51:   -c quality    quality from big images 0-100% (default: $ARG_BIGQALITY)
                     52:   -d dir        gallery dir (default: $ARG_DIR)
1.7       as         53:   -e exif       list of tags in hex. (default: $ARG_EXIF)
                     54:                 see: http://www.exiv2.org/tags.html
1.1       as         55:   -f files      gallery images
                     56:   -h            this page
                     57:   -i name       index file name (default: $ARG_INDEX)
1.6       as         58:   -l url        gallery link
1.1       as         59:   -n name       page title (default: $ARG_TITLE)
                     60:   -s suffix     list of suffix. if no \`\`-f'' defined, used to find images
                     61:                 in \`\`-d'' directoy. case insensitive
                     62:                 (default: $ARG_FILETYPES)
                     63:   -t size       size from thumbnail images in pixel (default: $ARG_TNSIZE)
                     64:   -u quality    quality from thumbnail images 0-100% (default: $ARG_BIGQALITY)
1.4       as         65:   -v            print version
                     66:   -C copyright  copyright (html) string (default: $ARG_COPYRIGHT)
1.6       as         67:   -F from       mail sender (default: $ARG_MAILFROM)
1.5       as         68:   -I file       info text file for pgallery. info file paras prefered.
                     69:                 the syntax of the file is MAKE(1)
1.6       as         70:                 supported variable: TITLE COPYRIGHT INDEX FILETYPES TNSIZE URL
                     71:                                     TNQALITY BIGSIZE BIGQALITY MAILTO MAILFROM
1.7       as         72:                                     EXIF
1.6       as         73:   -T mailto     send update infos to this address. if not set, no mail delivery
1.1       as         74:   -U            no update, new calculation of all images.
                     75:                 normally only new and modified images will calculated
                     76: USAGE
                     77:        exit
                     78: }
                     79: 
                     80: #
                     81: # get_my_path()
                     82: #
                     83: get_my_path()
                     84: {
                     85:        current=$(pwd)
                     86:        cd $(dirname $0)
                     87:        echo $(pwd)/$(basename $0)
                     88:        cd "$current"
                     89: }
                     90: 
                     91: #
                     92: # html_header()
                     93: #
                     94: html_header()
                     95: {
                     96:        cat <<HTML
                     97: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                     98: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                     99: <html xmlns="http://www.w3.org/1999/xhtml">
                    100: <head>
                    101:        <title>$ARG_TITLE</title>
                    102:                <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
                    103:                <style type="text/css">
                    104:                <!--
                    105: body {
                    106:        background-color: #464646;
                    107:        background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFgAAABYB\
                    108: AMAAACDuy0HAAAAG1BMVEX+/v4BAQH///8KCgoDAwN/f3/19fWAgID8/PzhDwT2AAAACXRSTlMFBQUFBQU\
                    109: FBQWHDtP9AAALwklEQVR4Xg3KOWOyWhAA0Bn2ci57eXEvQY1JCZp8sQTjVoJLTAkaE0swbj/7ve4UB37FL\
                    110: W4q86Lwwlh86J/ASAkpWaj+Krbb31HzH0Kjc2tIl7SADaWbpZBPE5dds6jJNyNdjAyKWqdroIixWRQIY6E\
                    111: /kOY7hIciL/ZfrAO3XP/06AuUJ3mSd/z95OB9vIal0DPlaZWHP7RE6DIXjmKqKkuGr+xNZylOnj1GSlUKv\
                    112: nxZDBOIzTfMe0fJgJ7c/GIIOdUuKxYyBFUOzvY6AC5AXx8R+o5O4S0j0wqBND3ErIYm/XHFbQjtH1MXD5d\
                    113: Ubp19OFdjkDlys+HSwrBgHRvL9wVN/pi8ViOIwcv/D1GRW6UuDvJLLQA5lCI17iUdsKYpOuYfMATGnpn/Z\
                    114: s3W6gov51G+/Vs9Ay//we5kh8uwvEPum6o5HkDMDb3ZWunwtq+UzENU8NphDdbvNtKM3knx5gi6UMSQl+e\
                    115: Gs+27mraDtxeWdH+T62Us/GylEtr7Ct8jlbeXKvAf5onx8D2uVt1J/GblV+XQyKUInOUG44fqjcszK266y\
                    116: HWAAYG9ekhvy4l4Maa44jYVyV2RFEuS54e2HcswtmNdqR/+V4P0O9e4XnpWgxVSQkNXpYMCxJ4Vel0lmi5\
                    117: 6jnYIIJAQMndF+zTEiyuj92r3ijJT1O0alPQnLWJvJLR7Xx7Xg9fm9QOqFu8o29m3QQqFwZN4bki/RoprN\
                    118: tMKKtEET9iMsJyKpkiguAorn2yzkv0wG3M1EEVDJP5VN7muLjYCglzdGQ7boYGgRmorzhRDq83gglgylC+\
                    119: hBLEyy6ZQWNwCmmqt6PvExAqGEA9V2XIT4/fS+I2cx1n5td85kOCjHfPWTg72FJ/+vKOyggt+rytFbEDJW\
                    120: L+mPwpgw6HtFLIHmq4o2m1nZ9saKwiKEOTVZtWlnqHODPu949VfKD+zzpfynd/ZZU5IWZ0dgnqRHC4uOBp\
                    121: BsT8N7YbFJzADiW2eo/T979OKFxY8zk/+HR/NNEkzgSBsmA35Sayz1m/ubxgmYQOmffyRh9gdx42mUVX51\
                    122: 2oqWkfxAzyuSCxx1cywx3jIXuXJEEbssymo0xMy7SskJW9C5IPYroPwQunt7f5FEPPXJLWRbGHcL4Q3sx3\
                    123: TLAN6W672r/I5CKkL6zSwwk0AI8+iBCSv1Y7QQP5RSoLE227uy8vn22Y6dhLBgEsRh18cTGjIv3y+60Kmt\
                    124: 3YAZQX8qf3bJDUc/5pdjti+KwAZ9GzzQzd23d1JBAnSvWkWB8YfsIGlspHitNiMPYPFfR+OecRuPyxgfoP\
                    125: 9/HkR3cR27IohiaDXCk/3VNP6lIxP9TBnsMeAAUZloq6P8KURLBsNFuiA3LsN/d9qpCeKKIBgSzsN5k+rd\
                    126: h3uh0VbvMuOIomJD1fBOiCqIsvklS5bOQhMaahJC+Rc+6lz+Uvxmq05Py+LoGIQlLKvlcaHsFG9Ui66H/q\
                    127: dHz67sPRGho+ruC92QgN5JEMmLsZREEiJu78FJbyzT8FsdK90XoEcezn2R5iLUzZhczJmf1yNY3gJNJUQv\
                    128: bpTznTAbnV5J8iL4q2OWuhJEndWVTyEr8M5VGTWtvOmUo1DsnOsqXE5ZzKE8K4/8cl8+c1XArp1RUKz+iK\
                    129: P96j2FcUmA+v0HnEr0iUdSrRK5duAj1FQamvpiaXR2JddD6g8n4SyFx/fjT4LkC+ghJckj1e1wP+DrHrpI\
                    130: iMaPH5F1rcaRvwZWfEn6fx+/C7PdXABGLNKjr1USZ5XyHjsafXMEoXtguAfjykMioMMHISXVAc9yQY5o5Q\
                    131: g8MM0nhWCA2HoiEgBc1EH+warLjxH3Ln68M/ciFqI1bG0mBOxiNreOuShEf/9pIzhm1Bh2cbYVxn2IYQ7e\
                    132: ljYpab/5EdPF2PSmcy+62j6e2HBPNbe+8JVMuRQBrWdL9uBh4bYbQaQJ07FyfcpCuvSuxUyYjP6avvw9gT\
                    133: cAj0uTVohSwOHDDaHTs8nyachMBcWoVDWp3/lWgqeCLMneAUhSuhD2RJpufLOSi7emxOVhYsOGomV2JCEK\
                    134: jWu7kuqwueyFEmDgVhR0l4oHn8W87UZuxb8id54SxHWiSnPKnMyAhzdhi2wN/AoH3OYwLajuybB8h/QeJJ\
                    135: iX1gIt+dfij+gr0CJRXQ2Y04Q6q8xHzfWm9FIgchiW0+X86tIotIGzRG1gENaKokQkLn+FXZ2x3KUcp7d/\
                    136: NUsmOmFCG/i03YB8pi0eiNS4LUIfA06AKvfQmP/VAXS1AP2kzJ+9LAaTafvFyO7bz8U9OCpld2q1eHGts+\
                    137: ZFrt04AmIlubOPP7Xayfi/r0tiX2aaPT9Dz4+TVPBoXsjHDzWfrmawOsZfmBT/k2+c6sz/hvD5wjrjT7Xg\
                    138: RlnEzPuZermi1jqfUrE3q7VdFfJu5oT9Ad+VUh1fIwIFhBy8TmMuhIeX2XpmogmvS1C3ZuwiyR87ZSrj0J\
                    139: v1DpEAYkbcL3RpjZXmZpPV4mXH8z8Nh8CS+R+PpcTnkhyr5UJaSiz0wjK22Ewl+zS+pTug0PQ0CSnJQ5Lf\
                    140: dR77vVZufgjkQ/ydf4V5zpEaNq+JZmrQK6WdZBacmMHL9RmLnPUs0/MYwYFzoyrXYQMTHGAUJOfumR5r79\
                    141: MZO28DIEXQVT5wGw99TY1T0GOCC/BzWv8READwICd0LjUNKnE6ORVa0lOnqhoO0v33lwWcwF0ynTgTpFxy\
                    142: +0OKdphNDWJlH8ubKoG6WJXtKxAwbsilpBJB+GBwimvTsCrv1R7LSX9ExkAw44ZEcxU3L50OHnKAyKZNe1\
                    143: fih+hVqItRGCDf7shuvme+lTWteX5oYuc58NrCaqjYIrIV0PFyQeh2ZzZEqNS60LuhnP5wweMkkaU93pDA\
                    144: /RWPNeGpPCBgiUeDvV0L1NfdRP/Hn5i7rUK7kftlIWeIUIYbtzzFl9nlIeaNfoX+x/qyWzIABLTZDbeq/h\
                    145: DZpxg2gkh+ICfSU8OUpJ8yWY17uQ5EGa+GGWFmnrBd9vX3KOteYkJaMpPwJ4TjzDjbhkOMKmWKClzVJ2g8\
                    146: 1YGFl/c0xPIKncgJGdUKvZoUUJu0gYaIAh6E0xNeQ15qpJXzNITgf4W+w/oUaKOM54EMUi1j5yvOCsEe8J\
                    147: YpwVGj53lNiPMY9Rltgd4icp82fvN69zkSBUI40nJSRTeHz7h1IX42Cr0klWjxjO05MSX1IaTeDmTRGEeK\
                    148: vAvtaaBaLQnjftGJz+4cjFyy6/iCjLGF2/gW+jQhEUxbEBPyQzXi+Bb4kc9wK4jIwNLWbwQAOtYKRLaipD\
                    149: H+X4TPPOG8DCNY4IC9yBk1qcibjhUgRnDcf35pl9d5otbvQjOIXlEu5dVtm5LRaK5KWcD/PX6LaGd25CuN\
                    150: HG/vgeIB1kcpCme+J8idlcjfBALAJSggznsGHGOAJgdGduMnZg+bAaeGASGV9bh/X2wPsVTmBLxmTTQsBG\
                    151: FkEOkZJTsGAm+HrtMDbWwvTXOutX1u7BxIq9Xib6DkFMbUitNdrYsULkahsAhBEh9FjdzL9BNARxTSr7T3\
                    152: u1rE+IWUmCIpwTZHZCu5l9THCuCcOhZqfekuQxjQ7EoyGUJAwCv/q1JOuJeCc/3lknb76zAquO/DAQhK/6\
                    153: 2cP8X2s3+IBLIhvL8RHopoHpIArJysYTTmMMeubPXh8W760AvMVH67jqgg06+/ne5MZ631z6yROhloh3dP\
                    154: QirZoEpr80wgt/cEbhbAQTmRLtGh8lxCwDBBb5OeJ4aEq25XBNMT2rzWedW2zIzj+CCDKlnlyJBzT81qBW\
                    155: p69h7vlb3TmEV+DNm2rqj1iT7BQuwVVsuPkwq1e5P8tgNjVbIlMzwXeM11kZqjx3KKFOJzc3CAyFVhi8fx\
                    156: VZ5FvhdAM5mM6kS6OgKu16MFglq3/b/QVIwdw7HUCyeW04JPjC5dO+GC9OfqfB4VX+wwuift+ths2Ss3i6\
                    157: nkOE+JFyD+wKFL+WMX6nwwDva0S1/O8Mlnida69Ph96fuFvCoRMvXnCfsLPPmC/hA5RnMNE4fDK0pVOQ4B\
                    158: HLaErzv/wD99ABmjNZk0AAAAABJRU5ErkJggg==");
                    159:        margin: 10px auto;
                    160:        font-family: Geneva,Arial,sans-serif;
                    161:        font-size: 12px;
1.2       as        162:        text-shadow: 1px 1px 1px #000;
1.7       as        163:        color: #808080;
1.1       as        164: }
                    165: div.tn {
                    166:        float: left;
                    167:        width: ${ARG_TNSIZE}px;
                    168:        height: ${ARG_TNSIZE}px;
                    169:        vertical-align:text-top;
                    170:        text-align: center;
                    171:        margin: 4px;
                    172: }
                    173: div.tn a {
                    174:        position: relative;
                    175:        display: inline-block;
                    176:        height: ${ARG_TNSIZE}px;
                    177: }
                    178: div.tn, div.big {
                    179:        background-color: black;
                    180:        border-width: 1px;
                    181:        border-style: solid;
                    182:        border-color: gray;
                    183:        box-shadow: 1px 1px 2px #000;
                    184:        padding: 1px;
1.4       as        185:        border-radius: 3px;
1.1       as        186: }
                    187: div.tn:hover {
                    188:        background-color: #222;
                    189: }
                    190: div.big {
                    191:        display: inline-block;
                    192:        width: ${ARG_BIGSIZE}px;
                    193: }
                    194: div.over {
                    195:        width: ${ARG_BIGSIZE}px;
                    196:        position: absolute;
                    197:        top: 30px;
                    198:        padding: 1px;
                    199: }
                    200: div.over a.left, div.over a.right {
                    201:        display: block;
1.2       as        202:        /* shell fuck of: missing CTLARI (shouldn't happen) - WTF?! */
                    203:        width: $(($ARG_BIGSIZE / 2))px;
1.1       as        204:        position: relative;
                    205:        top: 1px;
                    206:        left: 1px;
                    207:        background-repeat: no-repeat;
                    208: }
                    209: div.over a.left:hover {
                    210:        background-position: 5% center;
                    211:        background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAwC\
                    212: AYAAADtoXHnAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAh9JREFUeNrE2L1Lw0A\
                    213: UAHATSivSZii0ldpBnMU6SgYJpQUJDlk7dLV+LTqIiIv4B7kLolBKQRA6GLqUDMEhqKAlhUIR4125SHo0b\
                    214: XJ51x68pDSX+3G5I/dyguM4S/MuMfeHIAiQ7Yo+//+OocAYPm+jWEXxg8JC8erCgvt4AXrqgkkUJRRZ6jq\
                    215: G71EMRcAeil6wWq2uGYZx1ul0jjRNy5Jey6PauKcRJ5NIhklCoaE4QODNYDCwHVJ6vd5HIpE4xNdQxKOiM\
                    216: 0G3FIvFc4Imo6CBQV3XXwioje5jREOBkiQdE3SLFWUFFXJfaJQVLP2DIWdvFDA+9pYKiMKBAVFYMAAKD85\
                    217: A+YBTUH6gD8oXnIDyB31QviCFzgekUPxYVe4ghW7ixhRFueQKUmgZN9hut1s0aNv2V6FQOAUBqRvT+IAaX\
                    218: 6crWZb1hsqQJFfPkPnpJz6YpmnQlXK5XD6TycRIcrUDib7jQ71ev+v3+9/eSqlUKt1qtU4IvIFid2x9jDC\
                    219: muJE9PG6qql7jcaTHttvt6gh2J1MZYva6ees+d9jnjcQXnoDyh31WGb7wlPWUHzwjc+ADB8iR4OGA2SAsH\
                    220: CLvhYNDZvgwMMO3THSY8auNBS6xfrVFhZUoaGjYk+qA7DkEgmu12i1Bs1C7K1NhvLviecTLEOhEuFKpXDW\
                    221: bzcdGo/Egy/KFZzKJPHbMVsiEyVPXTRRPeMdMWMQuqLi0gPInwACOBcZx3lRFMwAAAABJRU5ErkJggg==");
                    222: }
                    223: div.over a.right:hover {
                    224:        background-position: 95% center;
                    225:        background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB0AAAAwC\
                    226: AYAAADtoXHnAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAiJJREFUeNrE2D1Lw0A\
                    227: YAOAmlNbBdii0FVM6OEu7SgcJpRUJDlk7dE21uuggIi7iD/IX+AGlFAXBDqVLyVCCBBW0JFhwMN7JHRxnY\
                    228: 5PcnX3hhSM58nB3+Xhzkud5sf8OiWjLPn2+eGF4gHEChLkOcgUdt0E+isAlhCVAbiGQjGeQ1yBdHjAeKZ7\
                    229: SCgR1Xc8Nh8M90zQPG42GAo7lQFZBLhOzwSXgKI1kMrk7mUxePBTT6dQB8Dk8B1IHmUbTLrOMFI8WjsIol\
                    230: 8tHHhW8YRKV0QWNwWDwIBKm0RK8aDqdbouEaRReQBUNkygJV0XCNBojnldh8CxUOOyHCoX/QoXB81AhcBC\
                    231: UOxwU5QqHQbnBYVFWODLKDEdFo8IanGYWNBSsquoJgkus6C+4UCgcOI7zRsP9fv8OoTWM8qh57mHlaFnWp\
                    232: 23bFn1SUZQiambm1bphYgMWddlsNp7P51fpk+Px2ETNV1YUf383Qa5BsNfr7adSqQzZyXXd91ardUmUs8x\
                    233: rWYNrBcD2aDQa0GsJ11fTtDO0ntssd28UcAfXzSxvpLBg5DcSKyhH/cowgVG+p8xg2MqBCximRuIGBq0Gu\
                    234: YJB6l7u4LwKXwjo9y8jFPT7a6uKBGehqmiQRhO45BAJ0ijcQTGazeaFSJBGl/DUkrsrvMFZa/pzE1UqleN\
                    235: Op3PV7XZv6vX6KU+QRMkdM3gzFal+TyBvQX7w3DGTFrELKscWEN8CDADBm8pgcciwqgAAAABJRU5ErkJgg\
                    236: g=="); 
                    237: }
                    238: div.big a {
                    239:        position: relative;
                    240:        display: inline-block;
                    241:        width: ${ARG_BIGSIZE}px;
                    242: }
                    243: div.box {
                    244:        text-align: center;
                    245:        width: ${ARG_BIGSIZE}px;
                    246:        margin: auto;
                    247: }
1.7       as        248: div.box div.d {
                    249:        width: ${ARG_BIGSIZE}px;
                    250:        padding: 5px;
                    251:        text-align: center;
                    252: }
                    253: div.box div.i {
1.1       as        254:        width: ${ARG_BIGSIZE}px;
                    255:        font-size: 90%;
                    256:        height: 25px;
                    257:        line-height: 25px;
                    258:        position: relative;
                    259: }
                    260: body > div.c {
                    261:        text-align: center;
                    262:        font-size: 90%;
                    263:        height: 25px;
                    264:        line-height: 25px;
                    265:        position: relative;
                    266:        margin: 4px;
                    267: }
                    268: a img {
                    269:        border-width: 0;
                    270: }
                    271: a {
                    272: }
                    273: div.nav {
                    274:        width: ${ARG_BIGSIZE}px;
                    275:        height: 20px;
                    276: }
                    277: div.nav a {
                    278:        color: #FFF;
                    279:        text-decoration: none;
                    280: }
                    281: div.nav a:hover {
                    282:        text-decoration: underline;
                    283: }
                    284: div.nav div.top {
                    285:        position: absolute;
                    286:        text-align: center;
1.2       as        287:        width: $(($ARG_BIGSIZE - 100))px;
                    288:        margin: 0 50px;
1.1       as        289: }
                    290: .left {
                    291:        float: left;
                    292: }
                    293: .right {
                    294:        float: right;
                    295: }
                    296: .clear {
                    297:        clear: both;
                    298: }
                    299:                -->
                    300:                </style>
                    301:        </head>
                    302: <body>
                    303: HTML
                    304: }
                    305: 
                    306: #
                    307: # html_footer()
                    308: #
                    309: html_footer()
                    310: {
                    311:        cat <<HTML
                    312: </body></html>
                    313: HTML
                    314: }
                    315: 
                    316: #
                    317: # html_tn()
                    318: #
                    319: html_tn()
                    320: {
                    321:        tn=$1
                    322:        link=$2
                    323: 
                    324:        info=$($BIN_IMGINFO -f $tn)
                    325:        width=$(echo $info | awk '{print $3}')
                    326:        height=$(echo $info | awk '{print $4}')
                    327:        top=$(($(($ARG_TNSIZE - $height)) / 2))
                    328: 
                    329:        cat <<HTML
                    330: <div class="tn">
                    331:        <a href="$link" style="top:${top}px">
                    332:                <img alt="$tn" width="$width" height="$height" src="$tn" />
                    333:        </a>
                    334: </div>
                    335: HTML
                    336: }
                    337: 
                    338: #
                    339: # html_img()
                    340: #
                    341: html_img()
                    342: {
1.7       as        343:        orig=$1
1.12      as        344:        num=$2
                    345:        all=$3
                    346:        img=$4
                    347:        link=$5
                    348:        linkb=$6
                    349:        linkn=$7
1.1       as        350: 
1.3       as        351:        info=$($BIN_IMGINFO -f $img)
                    352:        width=$(echo $info | awk '{print $3}')
                    353:        height=$(echo $info | awk '{print $4}')
1.1       as        354: 
1.7       as        355:        desc=$(get_exif_desc $orig)
                    356:        if [ "$desc" != "" ]
                    357:        then
                    358:                desc="<div class='d'>$desc</div>"
                    359:        fi
                    360: 
1.1       as        361:        if [ "$linkb" != "" ]
                    362:        then
1.12      as        363:                hlinkb="<a href='$linkb'>back</a>"
1.1       as        364:                olinkb="<a class='left' style='height:${height}px' href='$linkb'></a>"
                    365:        fi
                    366: 
                    367:        if [ "$linkn" != "" ]
                    368:        then
1.12      as        369:                hlinkn="<a href="$linkn">forward</a>"
1.1       as        370:                olinkn="<a class='right' style='height:${height}px' href='$linkn'></a>"
                    371:        fi
                    372: 
                    373:        cat <<HTML
                    374: <div class="box">
                    375:        <div class="nav">
1.12      as        376:                <div class="top">
                    377:                        <a href="$link">Index</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="$orig">original</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;$num/$all
                    378:                </div>
1.1       as        379:                <div class="left">$hlinkb</div>
                    380:                <div class="right">$hlinkn</div>
                    381:        </div>
                    382:        <div class="big">
1.3       as        383:                <img alt="$img" width="$width" height="$height" src="$img" />
1.1       as        384:        </div>
1.7       as        385:        $desc
                    386:        <div class="i">
                    387:                <div class="left">$(get_exif_info $orig)</div>
                    388:                <div class="right">$ARG_TITLE $ARG_COPYRIGHT</div>
1.1       as        389:        </div>
                    390:        <div class="over" style='height:${height}px'>
                    391:                $olinkb
                    392:                $olinkn
                    393:        </div>
                    394: </div>
                    395: HTML
                    396: }
                    397: 
                    398: #
                    399: # err
                    400: #
                    401: err()
                    402: {
                    403:        echo "$1" >&2
                    404:        exit 1
                    405: }
                    406: 
1.6       as        407: #
                    408: # mysendmail()
                    409: #
                    410: mysendmail()
                    411: {
                    412:        subject=$1
                    413:        (
                    414:                cat <<MAIL
                    415: From: $ARG_MAILFROM
                    416: To: $ARG_MAILTO
                    417: Subject: $subject
                    418: Content-Type: text/plain; charset=iso-8859-1
                    419: X-Mailer: $VERSION
                    420: 
                    421: $(cat)
                    422: MAIL
                    423:        ) | $BIN_SENDMAIL -t
                    424: }
1.1       as        425: 
1.7       as        426: #
                    427: # get_exif_desc()
                    428: #
                    429: get_exif_desc()
                    430: {
                    431:        img=$1
                    432:        $BIN_EXIF --ifd=0 --tag=0x010e -m $img 2> /dev/null | iconv -t ISO-8859-1 -f UTF-8 | while read line
                    433:        do
                    434:                echo "$line<br />"
                    435:        done
                    436: }
                    437: 
                    438: #
1.12      as        439: # get_exif_ts()
                    440: #
                    441: get_exif_ts()
                    442: {
                    443:        img=$1
                    444:        date=$($BIN_EXIF --ifd=EXIF --tag=0x9003 -m $img 2> /dev/null)
1.13    ! as        445:        if [ "$date" = "" ]
        !           446:        then
        !           447:                echo "-1"
        !           448:                return 1
        !           449:        fi
1.12      as        450:        date -j -f "%Y:%m:%d %T" "$date" "+%s"
                    451: }
                    452: 
                    453: #
                    454: # get_exif_date()
                    455: #
                    456: get_exif_date()
                    457: {
                    458:        img=$1
                    459:        ts=$(get_exif_ts $img) && date -r $ts "+%d.%m.%Y %H:%M" || echo ""
                    460: }
                    461: 
                    462: #
1.7       as        463: # get_exif_value()
                    464: #
                    465: get_exif_value()
                    466: {
                    467:        img=$1
                    468:        hex=$2
                    469:        $BIN_EXIFTRAN -d $img | grep $hex | sed -E 's/^.{45}//'
                    470: }
                    471: 
                    472: #
                    473: # get_exif_info()
                    474: #
                    475: get_exif_info()
                    476: {
                    477:        img=$1
1.12      as        478: 
1.7       as        479:        exifinfo=
1.12      as        480:        created=$(get_exif_date $img) && exifinfo="$created / "
                    481: 
1.7       as        482:        for exif in $ARG_EXIF
                    483:        do
                    484:                if echo $exif | grep -q -E '0x[[:alnum:]]{4}'
                    485:                then
                    486:                        exifinfo="$exifinfo$(get_exif_value $img $exif) "
                    487:                else
                    488:                        exifinfo="$exifinfo$exif "
                    489:                fi
                    490:        done
1.12      as        491:        echo $exifinfo | sed -E -e 's/ mm /mm /' -e 's/ sec./s/' -e 's/ ISO / ISO/' -e 's/ ISO(\/| )/ \1/'
1.7       as        492: }
                    493: 
1.11      as        494: #
                    495: # is_in_list()
                    496: #
                    497: is_in_list()
                    498: {
                    499:        list=$1
                    500:        value=$2
                    501:        for entry in $list
                    502:        do
                    503:                test "$entry" = "$value" && return 0
                    504:        done
                    505:        return 1
                    506: }
                    507: 
1.1       as        508: # parse args
                    509: while [ "$1" != "" ]
                    510: do
                    511:        arg=$1
                    512:        shift
                    513:        case $arg in
                    514:                -h)
1.6       as        515:                        usage;;
1.1       as        516:                -n)
                    517:                        ARG_TITLE=$1
1.6       as        518:                        shift;;
1.1       as        519:                -t)
                    520:                        ARG_TNSIZE=$1
1.6       as        521:                        shift;;
1.1       as        522:                -u)
                    523:                        ARG_TNQALITY=$1
1.6       as        524:                        shift;;
1.1       as        525:                -b)
                    526:                        ARG_BIGSIZE=$1
1.6       as        527:                        shift;;
1.1       as        528:                -c)
                    529:                        ARG_BIGQALITY=$1
1.6       as        530:                        shift;;
1.1       as        531:                -f)
                    532:                        ARG_FILES=$1
1.6       as        533:                        shift;;
                    534:                -l)
                    535:                        ARG_URL=$1
                    536:                        shift;;
1.1       as        537:                -s)
                    538:                        ARG_FILETYPES=$1
1.6       as        539:                        shift;;
1.1       as        540:                -d)
                    541:                        ARG_DIR=$1
1.6       as        542:                        shift;;
1.7       as        543:                -e)
                    544:                        ARG_EXIF=$1
                    545:                        shift;;
1.1       as        546:                -C)
                    547:                        ARG_COPYRIGHT=$1
1.6       as        548:                        shift;;
                    549:                -F)
                    550:                        ARG_MAILFROM=$1
                    551:                        shift;;
1.5       as        552:                -I)
                    553:                        ARG_INFOFILE=$1
1.6       as        554:                        shift;;
                    555:                -T)
                    556:                        ARG_MAILTO=$1
                    557:                        shift;;
1.1       as        558:                -U)
1.6       as        559:                        ARG_UPDATE=0;;
1.1       as        560:                -v)
                    561:                        echo $VERSION
1.6       as        562:                        exit;;
1.1       as        563:                *)
                    564:                        echo "unknown argument $arg"
                    565:                        exit
                    566:        esac
                    567: done
                    568: 
1.5       as        569: # parese info file
                    570: if [ "$ARG_INFOFILE" != "" ]
                    571: then
                    572:        test -f $ARG_INFOFILE || err "info file not found \`\`$ARG_INFOFILE''"
1.6       as        573:        for n in TITLE COPYRIGHT INDEX FILETYPES TNSIZE TNQALITY BIGSIZE \
1.7       as        574:                BIGQALITY MAILTO MAILFROM URL EXIF
1.5       as        575:        do
                    576:                v=$(make -f $ARG_INFOFILE -V$n)
                    577:                test "$v" = "" && continue
                    578:                eval "ARG_$n='$v'"
                    579:        done    
                    580: fi
                    581: 
1.6       as        582: # go to gallery directory
1.1       as        583: MY=$(get_my_path)
                    584: cd "$ARG_DIR" || exit 1
                    585: 
1.6       as        586: # fix url
                    587: if [ "$ARG_URL" != "" ]
                    588: then
                    589:        echo "$ARG_URL" | grep -q '/$' || ARG_URL="${ARG_URL}/"
                    590: fi
                    591: 
1.1       as        592: # if no images defined, find files
                    593: if [ "$ARG_FILES" = "" -a "$ARG_FILETYPES" != "" ]
                    594: then
                    595:        match=
                    596:        for type in $ARG_FILETYPES
                    597:        do
                    598:                match="$match *.$(echo $type | tr '[:lower:]' '[:upper:]')"
                    599:                match="$match *.$(echo $type | tr '[:upper:]' '[:lower:]')"
                    600:        done
                    601:        ARG_FILES=$(cd $ARG_DIR && ls $match 2>/dev/null)
                    602: fi
                    603: 
                    604: # Filter big and thumbnails
                    605: echo -n "find images"
                    606: FLIST=
                    607: for file in $ARG_FILES
                    608: do
                    609:        test $(echo $file | grep -E '\.(tn|big)\.jpg$') && continue
                    610:        FLIST="$FLIST $file"
                    611:        echo -n " $file"
                    612: done
                    613: echo 
                    614: 
                    615: test $(echo $FLIST | wc -w) -eq 0 && err "error: no image found in \`\`$ARG_DIR''"
                    616: 
1.13    ! as        617: # use exif createtime to order images
        !           618: FLIST=$(
        !           619:        (
        !           620:                for file in $FLIST
        !           621:                do
        !           622:                        echo "$(get_exif_ts $file) $file"
        !           623:                done
        !           624:        ) | sort -n | awk '{print $2}'
        !           625: )
        !           626: 
1.5       as        627: # find new and to update images
                    628: FLIST_NEW=
                    629: FLIST_UPDATE=
                    630: echo "all: tns" > $MKAKEFILE
                    631: targets=""
                    632: for file in $FLIST
                    633: do
                    634:        tn="${file}.tn.jpg"
                    635:        if [ ! -f $tn ]
                    636:        then
                    637:                FLIST_NEW="$FLIST_NEW $file"
                    638:                continue
                    639:        fi
                    640: 
                    641:        targets="$targets $tn"
                    642:        (
                    643:                cat <<MAKE
                    644: $tn: $file
                    645:        @echo ${file}
                    646: MAKE
                    647:        ) >> $MKAKEFILE
                    648: done
                    649: echo "tns: $targets" >> $MKAKEFILE
                    650: FLIST_UPDATE=$(make -f $MKAKEFILE)
                    651: rm $MKAKEFILE
                    652: 
                    653: # update and no new and update images found
                    654: if [ $ARG_UPDATE -eq 1 -a "$FLIST_NEW" = "" -a "$FLIST_UPDATE" = "" ]
                    655: then
                    656:        echo nothing to do
                    657:        exit 1
                    658: fi
                    659: 
                    660: if [ $ARG_UPDATE -eq 1 ]
                    661: then
                    662:        echo new images: $FLIST_NEW
                    663:        echo update images: $FLIST_UPDATE
                    664: fi
                    665: 
1.1       as        666: # Create make file to rotate und convert all big and thumbnails.
                    667: # Is needed to define the new real image sizes.
                    668: echo "all: tns" > $MKAKEFILE
                    669: targets=""
                    670: for file in $FLIST
                    671: do
                    672:        tn="${file}.tn.jpg"
                    673:        big="${file}.big.jpg"
                    674:        targets="$targets $tn"
                    675: 
                    676:        target=
                    677:        if [ $ARG_UPDATE -eq 1 ]
                    678:        then
                    679:                target="$tn: $ME $file"
                    680:        else
                    681:                target="$tn::"
                    682:        fi
                    683: 
                    684:        (
1.5       as        685:                cat <<MAKE
1.1       as        686: $target
                    687:        $BIN_EXIFAUTOTRAN $file
                    688:        $BIN_CONVERT -verbose -thumbnail ${ARG_TNSIZE}x${ARG_TNSIZE} -quality $ARG_TNQALITY $file $tn
                    689:        $BIN_CONVERT -verbose -thumbnail ${ARG_BIGSIZE}x${ARG_BIGSIZE} -quality $ARG_BIGQALITY $file $big
                    690: MAKE
                    691:        ) >> $MKAKEFILE
                    692: done
                    693: echo "tns: $targets" >> $MKAKEFILE
                    694: 
1.12      as        695: #make -f $MKAKEFILE
1.1       as        696: rm $MKAKEFILE
                    697: 
1.10      as        698: # create html index
                    699: index=""
                    700: for file in $FLIST
                    701: do
                    702:        tn="${file}.tn.jpg"
                    703:        imglink="${file}.html"
                    704:        index="$index $(html_tn $tn $imglink)"
                    705: done
                    706: echo create html index
                    707: (
                    708:        html_header
                    709:        echo $index
                    710:        echo "<div class='clear'></div>"
                    711:        echo "<div class='c'>$ARG_TITLE $ARG_COPYRIGHT</div>"
                    712:        html_footer
                    713: ) > $ARG_INDEX
                    714: 
1.1       as        715: # create single html files
1.11      as        716: #test $ARG_UPDATE -eq 1 && FLIST="$FLIST_NEW $FLIST_UPDATE"
1.1       as        717: i=0
1.12      as        718: all=$(echo $FLIST | wc -w)
1.1       as        719: echo -n "create single html files "
                    720: for file in $FLIST
                    721: do
                    722:        h=$i
                    723:        i=$(($i + 1))
                    724:        j=$(($i + 1))
                    725: 
1.11      as        726:        # is update mod and no new images founded
                    727:        if [ $ARG_UPDATE -eq 1 -a "$FLIST_NEW" = "" ]
                    728:        then
                    729:                is_in_list "$FLIST_UPDATE" "$file" || continue
                    730:        fi
                    731: 
1.1       as        732:        big="${file}.big.jpg"
                    733:        imglink="${file}.html"
                    734: 
                    735:        if [ $i -ne 1 ]
                    736:        then
                    737:                linkb=$(echo $FLIST | awk "{print \$$h}").html
                    738:        fi
                    739:        linkn=$(echo $FLIST | awk "{print \$$j}")
                    740:        test "$linkn" != "" && linkn="$linkn.html"
                    741: 
                    742:        echo -n .
                    743:        (
                    744:                html_header
1.12      as        745:                html_img $file $i $all $big $ARG_INDEX "$linkb" "$linkn"
1.1       as        746:                html_footer
                    747:        ) > $imglink
                    748: done
                    749: echo
                    750: 
1.6       as        751: test "$ARG_MAILTO" = "" && exit 0
                    752: 
                    753: # send info mail
                    754: if [ "$FLIST_NEW" != "" -o "$FLIST_UPDATE" != "" ]
                    755: then
                    756:        echo "send mail to $ARG_MAILTO"
                    757:        (
                    758:                echo "Hallo,"
                    759:                echo
                    760:                echo -n "the gallery $ARG_TITLE has been updated"
                    761:                if [ "$ARG_URL" != "" ]
                    762:                then
                    763:                        echo ":"
                    764:                        echo $ARG_URL
                    765:                else
                    766:                        echo "."
                    767:                fi
                    768: 
                    769:                suffix=
                    770:                test "$ARG_URL" != "" && suffix=.html
                    771: 
                    772:                if [ "$FLIST_NEW" != "" ]
                    773:                then
                    774:                        echo
                    775:                        echo "add pictures:"
                    776:                        for file in $FLIST_NEW
                    777:                        do
                    778:                                echo "- ${ARG_URL}${file}${suffix}"
                    779:                        done
                    780:                fi
                    781: 
                    782:                if [ "$FLIST_UPDATE" != "" ]
                    783:                then
                    784:                        echo
                    785:                        echo "update pictures:"
                    786:                        for file in $FLIST_UPDATE
                    787:                        do
                    788:                                echo "- ${ARG_URL}${file}${suffix}"
                    789:                        done
                    790:                fi
                    791:        ) | mysendmail "PGallery Update: $ARG_TITLE"
                    792: fi