1188N/A#!/bin/ksh
1188N/A
1188N/AUsage() {
1188N/A printf 'Usage: %s [-p] [-n] [-h] [image_dir]
1188N/A
1188N/A Options:
1188N/A -p .. Combine straight to PNG. Otherwise first pics are combined into a
1188N/A GIF and than converted to PNG.
1188N/A -n .. No action, i.e. show what would be done without actually doing it.
1188N/A -h .. Print this help and exit.
1188N/A
1188N/A Combines several images into a sprite named combined.png and prints out
1188N/A the required CSS infos. E.g.:
1188N/A
1389N/A %s web/static/offwhite/img
1188N/A' "$(basename $0)" "$(basename $0)"
1188N/A}
1188N/A
1188N/AGIF="gif"
1188N/AECHO=""
1188N/Awhile getopts "h(help)n(dry)p(png)" option ; do
1188N/A case "$option" in
1188N/A h) Usage ; exit 0 ;;
1188N/A p) GIF="png" ;;
1188N/A n) ECHO="echo" ;;
1188N/A esac
1188N/Adone
1188N/AIDX=$(($OPTIND-1))
1188N/Ashift $IDX
1188N/A
1188N/Aif [ -n "$1" ]; then
1188N/A cd "$1"
1188N/A [ $? -eq 0 ] || exit 1
1188N/Afi
1389N/AF_NAV="h.gif l.gif w.gif a.gif lno.gif slst.gif"
1389N/AF_LST="do.gif d.gif p.gif"
1389N/AF_MISC="Logo.png servedby.png rss.png btn_close.gif q.gif" # q.gif must be the last
1188N/A
1188N/AFILES="$F_MISC $F_LST $F_NAV"
1188N/AFILES="$F_NAV $F_LST $F_MISC"
1188N/A
1188N/AOUT="combined"
1188N/A
1188N/A# concat to GIF (results in smaller pics than to PNG directly)
1188N/A$ECHO montage -background Transparent -tile x1 -mode Concatenate $FILES ${OUT}.$GIF
1188N/Aif [ "$GIF" = "gif" ]; then
1389N/A# convert to PNG (transparent gifs are rendered badly by FF on none-transparent
1389N/A# BGs. Converting it manually e.g. with Gimp may produce better results.)
1188N/A$ECHO convert ${OUT}.$GIF ${OUT}.png
1188N/Afi
1188N/A
1188N/Ainteger X=0
1188N/A[ -n "$ECHO" ] && $ECHO "identify -format '%f %w %h\\\n' $FILES $OUT.png"
1188N/Aidentify -format "%f %w %h\n" $FILES $OUT.png | while read F W H T; do
1188N/A [ -z "$F" ] && continue
1188N/A printf "%s background-position: -%dpx %dpx; width: %dpx; height: %dpx;\n" \
1188N/A "$F" $X 0 $W $H
1188N/A X=$((X+$W))
1188N/Adone