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

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.11    ! as          8: # $Paefchen: scripts/pgallery/src/pgallery.sh,v 1.10 2012/08/29 10:52: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:        left: 4px;
                    260: }
                    261: body > div.c {
                    262:        text-align: center;
                    263:        font-size: 90%;
                    264:        height: 25px;
                    265:        line-height: 25px;
                    266:        position: relative;
                    267:        margin: 4px;
                    268: }
                    269: a img {
                    270:        border-width: 0;
                    271: }
                    272: a {
                    273: }
                    274: div.nav {
                    275:        width: ${ARG_BIGSIZE}px;
                    276:        height: 20px;
                    277: }
                    278: div.nav a {
                    279:        color: #FFF;
                    280:        text-decoration: none;
                    281: }
                    282: div.nav a:hover {
                    283:        text-decoration: underline;
                    284: }
                    285: div.nav div.top {
                    286:        position: absolute;
                    287:        text-align: center;
1.2       as        288:        width: $(($ARG_BIGSIZE - 100))px;
                    289:        margin: 0 50px;
1.1       as        290: }
                    291: .left {
                    292:        float: left;
                    293: }
                    294: .right {
                    295:        float: right;
                    296: }
                    297: .clear {
                    298:        clear: both;
                    299: }
                    300:                -->
                    301:                </style>
                    302:        </head>
                    303: <body>
                    304: HTML
                    305: }
                    306: 
                    307: #
                    308: # html_footer()
                    309: #
                    310: html_footer()
                    311: {
                    312:        cat <<HTML
                    313: </body></html>
                    314: HTML
                    315: }
                    316: 
                    317: #
                    318: # html_tn()
                    319: #
                    320: html_tn()
                    321: {
                    322:        tn=$1
                    323:        link=$2
                    324: 
                    325:        info=$($BIN_IMGINFO -f $tn)
                    326:        width=$(echo $info | awk '{print $3}')
                    327:        height=$(echo $info | awk '{print $4}')
                    328:        top=$(($(($ARG_TNSIZE - $height)) / 2))
                    329: 
                    330:        cat <<HTML
                    331: <div class="tn">
                    332:        <a href="$link" style="top:${top}px">
                    333:                <img alt="$tn" width="$width" height="$height" src="$tn" />
                    334:        </a>
                    335: </div>
                    336: HTML
                    337: }
                    338: 
                    339: #
                    340: # html_img()
                    341: #
                    342: html_img()
                    343: {
1.7       as        344:        orig=$1
                    345:        img=$2
                    346:        link=$3
                    347:        linkb=$4
                    348:        linkn=$5
1.1       as        349: 
1.3       as        350:        info=$($BIN_IMGINFO -f $img)
                    351:        width=$(echo $info | awk '{print $3}')
                    352:        height=$(echo $info | awk '{print $4}')
1.1       as        353: 
1.7       as        354:        desc=$(get_exif_desc $orig)
                    355:        if [ "$desc" != "" ]
                    356:        then
                    357:                desc="<div class='d'>$desc</div>"
                    358:        fi
                    359: 
1.1       as        360:        if [ "$linkb" != "" ]
                    361:        then
                    362:                hlinkb="<a href='$linkb'>zurück</a>"
                    363:                olinkb="<a class='left' style='height:${height}px' href='$linkb'></a>"
                    364:        fi
                    365: 
                    366:        if [ "$linkn" != "" ]
                    367:        then
                    368:                hlinkn="<a href="$linkn">weiter</a>"
                    369:                olinkn="<a class='right' style='height:${height}px' href='$linkn'></a>"
                    370:        fi
                    371: 
                    372:        cat <<HTML
                    373: <div class="box">
                    374:        <div class="nav">
1.2       as        375:                <div class="top"><a href="$link">Index</a></div>
1.1       as        376:                <div class="left">$hlinkb</div>
                    377:                <div class="right">$hlinkn</div>
                    378:        </div>
                    379:        <div class="big">
1.3       as        380:                <img alt="$img" width="$width" height="$height" src="$img" />
1.1       as        381:        </div>
1.7       as        382:        $desc
                    383:        <div class="i">
                    384:                <div class="left">$(get_exif_info $orig)</div>
                    385:                <div class="right">$ARG_TITLE $ARG_COPYRIGHT</div>
1.1       as        386:        </div>
                    387:        <div class="over" style='height:${height}px'>
                    388:                $olinkb
                    389:                $olinkn
                    390:        </div>
                    391: </div>
                    392: HTML
                    393: }
                    394: 
                    395: #
                    396: # err
                    397: #
                    398: err()
                    399: {
                    400:        echo "$1" >&2
                    401:        exit 1
                    402: }
                    403: 
1.6       as        404: #
                    405: # mysendmail()
                    406: #
                    407: mysendmail()
                    408: {
                    409:        subject=$1
                    410:        (
                    411:                cat <<MAIL
                    412: From: $ARG_MAILFROM
                    413: To: $ARG_MAILTO
                    414: Subject: $subject
                    415: Content-Type: text/plain; charset=iso-8859-1
                    416: X-Mailer: $VERSION
                    417: 
                    418: $(cat)
                    419: MAIL
                    420:        ) | $BIN_SENDMAIL -t
                    421: }
1.1       as        422: 
1.7       as        423: #
                    424: # get_exif_desc()
                    425: #
                    426: get_exif_desc()
                    427: {
                    428:        img=$1
                    429:        $BIN_EXIF --ifd=0 --tag=0x010e -m $img 2> /dev/null | iconv -t ISO-8859-1 -f UTF-8 | while read line
                    430:        do
                    431:                echo "$line<br />"
                    432:        done
                    433: }
                    434: 
                    435: #
                    436: # get_exif_value()
                    437: #
                    438: get_exif_value()
                    439: {
                    440:        img=$1
                    441:        hex=$2
                    442:        $BIN_EXIFTRAN -d $img | grep $hex | sed -E 's/^.{45}//'
                    443: }
                    444: 
                    445: #
                    446: # get_exif_info()
                    447: #
                    448: get_exif_info()
                    449: {
                    450:        img=$1
                    451:        exifinfo=
                    452:        for exif in $ARG_EXIF
                    453:        do
                    454:                if echo $exif | grep -q -E '0x[[:alnum:]]{4}'
                    455:                then
                    456:                        exifinfo="$exifinfo$(get_exif_value $img $exif) "
                    457:                else
                    458:                        exifinfo="$exifinfo$exif "
                    459:                fi
                    460:        done
1.8       as        461:        echo $exifinfo | sed -e 's/ mm /mm /' -e 's/ sec./s/' -e 's/ ISO / ISO/'
1.7       as        462: }
                    463: 
1.11    ! as        464: #
        !           465: # is_in_list()
        !           466: #
        !           467: is_in_list()
        !           468: {
        !           469:        list=$1
        !           470:        value=$2
        !           471:        for entry in $list
        !           472:        do
        !           473:                test "$entry" = "$value" && return 0
        !           474:        done
        !           475:        return 1
        !           476: }
        !           477: 
1.1       as        478: # parse args
                    479: while [ "$1" != "" ]
                    480: do
                    481:        arg=$1
                    482:        shift
                    483:        case $arg in
                    484:                -h)
1.6       as        485:                        usage;;
1.1       as        486:                -n)
                    487:                        ARG_TITLE=$1
1.6       as        488:                        shift;;
1.1       as        489:                -t)
                    490:                        ARG_TNSIZE=$1
1.6       as        491:                        shift;;
1.1       as        492:                -u)
                    493:                        ARG_TNQALITY=$1
1.6       as        494:                        shift;;
1.1       as        495:                -b)
                    496:                        ARG_BIGSIZE=$1
1.6       as        497:                        shift;;
1.1       as        498:                -c)
                    499:                        ARG_BIGQALITY=$1
1.6       as        500:                        shift;;
1.1       as        501:                -f)
                    502:                        ARG_FILES=$1
1.6       as        503:                        shift;;
                    504:                -l)
                    505:                        ARG_URL=$1
                    506:                        shift;;
1.1       as        507:                -s)
                    508:                        ARG_FILETYPES=$1
1.6       as        509:                        shift;;
1.1       as        510:                -d)
                    511:                        ARG_DIR=$1
1.6       as        512:                        shift;;
1.7       as        513:                -e)
                    514:                        ARG_EXIF=$1
                    515:                        shift;;
1.1       as        516:                -C)
                    517:                        ARG_COPYRIGHT=$1
1.6       as        518:                        shift;;
                    519:                -F)
                    520:                        ARG_MAILFROM=$1
                    521:                        shift;;
1.5       as        522:                -I)
                    523:                        ARG_INFOFILE=$1
1.6       as        524:                        shift;;
                    525:                -T)
                    526:                        ARG_MAILTO=$1
                    527:                        shift;;
1.1       as        528:                -U)
1.6       as        529:                        ARG_UPDATE=0;;
1.1       as        530:                -v)
                    531:                        echo $VERSION
1.6       as        532:                        exit;;
1.1       as        533:                *)
                    534:                        echo "unknown argument $arg"
                    535:                        exit
                    536:        esac
                    537: done
                    538: 
1.5       as        539: # parese info file
                    540: if [ "$ARG_INFOFILE" != "" ]
                    541: then
                    542:        test -f $ARG_INFOFILE || err "info file not found \`\`$ARG_INFOFILE''"
1.6       as        543:        for n in TITLE COPYRIGHT INDEX FILETYPES TNSIZE TNQALITY BIGSIZE \
1.7       as        544:                BIGQALITY MAILTO MAILFROM URL EXIF
1.5       as        545:        do
                    546:                v=$(make -f $ARG_INFOFILE -V$n)
                    547:                test "$v" = "" && continue
                    548:                eval "ARG_$n='$v'"
                    549:        done    
                    550: fi
                    551: 
1.6       as        552: # go to gallery directory
1.1       as        553: MY=$(get_my_path)
                    554: cd "$ARG_DIR" || exit 1
                    555: 
1.6       as        556: # fix url
                    557: if [ "$ARG_URL" != "" ]
                    558: then
                    559:        echo "$ARG_URL" | grep -q '/$' || ARG_URL="${ARG_URL}/"
                    560: fi
                    561: 
1.1       as        562: # if no images defined, find files
                    563: if [ "$ARG_FILES" = "" -a "$ARG_FILETYPES" != "" ]
                    564: then
                    565:        match=
                    566:        for type in $ARG_FILETYPES
                    567:        do
                    568:                match="$match *.$(echo $type | tr '[:lower:]' '[:upper:]')"
                    569:                match="$match *.$(echo $type | tr '[:upper:]' '[:lower:]')"
                    570:        done
                    571:        ARG_FILES=$(cd $ARG_DIR && ls $match 2>/dev/null)
                    572: fi
                    573: 
                    574: # Filter big and thumbnails
                    575: echo -n "find images"
                    576: FLIST=
                    577: for file in $ARG_FILES
                    578: do
                    579:        test $(echo $file | grep -E '\.(tn|big)\.jpg$') && continue
                    580:        FLIST="$FLIST $file"
                    581:        echo -n " $file"
                    582: done
                    583: echo 
                    584: 
                    585: test $(echo $FLIST | wc -w) -eq 0 && err "error: no image found in \`\`$ARG_DIR''"
                    586: 
1.5       as        587: # find new and to update images
                    588: FLIST_NEW=
                    589: FLIST_UPDATE=
                    590: echo "all: tns" > $MKAKEFILE
                    591: targets=""
                    592: for file in $FLIST
                    593: do
                    594:        tn="${file}.tn.jpg"
                    595:        if [ ! -f $tn ]
                    596:        then
                    597:                FLIST_NEW="$FLIST_NEW $file"
                    598:                continue
                    599:        fi
                    600: 
                    601:        targets="$targets $tn"
                    602:        (
                    603:                cat <<MAKE
                    604: $tn: $file
                    605:        @echo ${file}
                    606: MAKE
                    607:        ) >> $MKAKEFILE
                    608: done
                    609: echo "tns: $targets" >> $MKAKEFILE
                    610: FLIST_UPDATE=$(make -f $MKAKEFILE)
                    611: rm $MKAKEFILE
                    612: 
                    613: # update and no new and update images found
                    614: if [ $ARG_UPDATE -eq 1 -a "$FLIST_NEW" = "" -a "$FLIST_UPDATE" = "" ]
                    615: then
                    616:        echo nothing to do
                    617:        exit 1
                    618: fi
                    619: 
                    620: if [ $ARG_UPDATE -eq 1 ]
                    621: then
                    622:        echo new images: $FLIST_NEW
                    623:        echo update images: $FLIST_UPDATE
                    624: fi
                    625: 
1.1       as        626: # Create make file to rotate und convert all big and thumbnails.
                    627: # Is needed to define the new real image sizes.
                    628: echo "all: tns" > $MKAKEFILE
                    629: targets=""
                    630: for file in $FLIST
                    631: do
                    632:        tn="${file}.tn.jpg"
                    633:        big="${file}.big.jpg"
                    634:        targets="$targets $tn"
                    635: 
                    636:        target=
                    637:        if [ $ARG_UPDATE -eq 1 ]
                    638:        then
                    639:                target="$tn: $ME $file"
                    640:        else
                    641:                target="$tn::"
                    642:        fi
                    643: 
                    644:        (
1.5       as        645:                cat <<MAKE
1.1       as        646: $target
                    647:        $BIN_EXIFAUTOTRAN $file
                    648:        $BIN_CONVERT -verbose -thumbnail ${ARG_TNSIZE}x${ARG_TNSIZE} -quality $ARG_TNQALITY $file $tn
                    649:        $BIN_CONVERT -verbose -thumbnail ${ARG_BIGSIZE}x${ARG_BIGSIZE} -quality $ARG_BIGQALITY $file $big
                    650: MAKE
                    651:        ) >> $MKAKEFILE
                    652: done
                    653: echo "tns: $targets" >> $MKAKEFILE
                    654: 
                    655: make -f $MKAKEFILE
                    656: rm $MKAKEFILE
                    657: 
1.10      as        658: # create html index
                    659: index=""
                    660: for file in $FLIST
                    661: do
                    662:        tn="${file}.tn.jpg"
                    663:        imglink="${file}.html"
                    664:        index="$index $(html_tn $tn $imglink)"
                    665: done
                    666: echo create html index
                    667: (
                    668:        html_header
                    669:        echo $index
                    670:        echo "<div class='clear'></div>"
                    671:        echo "<div class='c'>$ARG_TITLE $ARG_COPYRIGHT</div>"
                    672:        html_footer
                    673: ) > $ARG_INDEX
                    674: 
1.1       as        675: # create single html files
1.11    ! as        676: #test $ARG_UPDATE -eq 1 && FLIST="$FLIST_NEW $FLIST_UPDATE"
1.1       as        677: i=0
                    678: echo -n "create single html files "
                    679: for file in $FLIST
                    680: do
                    681:        h=$i
                    682:        i=$(($i + 1))
                    683:        j=$(($i + 1))
                    684: 
1.11    ! as        685:        # is update mod and no new images founded
        !           686:        if [ $ARG_UPDATE -eq 1 -a "$FLIST_NEW" = "" ]
        !           687:        then
        !           688:                is_in_list "$FLIST_UPDATE" "$file" || continue
        !           689:        fi
        !           690: 
1.1       as        691:        big="${file}.big.jpg"
                    692:        imglink="${file}.html"
                    693: 
                    694:        if [ $i -ne 1 ]
                    695:        then
                    696:                linkb=$(echo $FLIST | awk "{print \$$h}").html
                    697:        fi
                    698:        linkn=$(echo $FLIST | awk "{print \$$j}")
                    699:        test "$linkn" != "" && linkn="$linkn.html"
                    700: 
                    701:        echo -n .
                    702:        (
                    703:                html_header
1.7       as        704:                html_img $file $big $ARG_INDEX "$linkb" "$linkn"
1.1       as        705:                html_footer
                    706:        ) > $imglink
                    707: done
                    708: echo
                    709: 
1.6       as        710: test "$ARG_MAILTO" = "" && exit 0
                    711: 
                    712: # send info mail
                    713: if [ "$FLIST_NEW" != "" -o "$FLIST_UPDATE" != "" ]
                    714: then
                    715:        echo "send mail to $ARG_MAILTO"
                    716:        (
                    717:                echo "Hallo,"
                    718:                echo
                    719:                echo -n "the gallery $ARG_TITLE has been updated"
                    720:                if [ "$ARG_URL" != "" ]
                    721:                then
                    722:                        echo ":"
                    723:                        echo $ARG_URL
                    724:                else
                    725:                        echo "."
                    726:                fi
                    727: 
                    728:                suffix=
                    729:                test "$ARG_URL" != "" && suffix=.html
                    730: 
                    731:                if [ "$FLIST_NEW" != "" ]
                    732:                then
                    733:                        echo
                    734:                        echo "add pictures:"
                    735:                        for file in $FLIST_NEW
                    736:                        do
                    737:                                echo "- ${ARG_URL}${file}${suffix}"
                    738:                        done
                    739:                fi
                    740: 
                    741:                if [ "$FLIST_UPDATE" != "" ]
                    742:                then
                    743:                        echo
                    744:                        echo "update pictures:"
                    745:                        for file in $FLIST_UPDATE
                    746:                        do
                    747:                                echo "- ${ARG_URL}${file}${suffix}"
                    748:                        done
                    749:                fi
                    750:        ) | mysendmail "PGallery Update: $ARG_TITLE"
                    751: fi