3 if [[ -z "$MUSIC" ]]; then
7 thumbs="$HOME/.fvwm/.thumbs"
9 if ! [[ -d "$thumbs" ]]; then
10 mkdir "$thumbs" || exit 1
17 while [[ "${1#--}" != "$1" && "$1" != "-" ]]; do
18 if [[ "$1" == "--small" ]]; then
20 elif [[ "$1" == "--size" ]]; then
23 elif [[ "$1" = "--music" ]]; then
25 elif [[ "$1" = "--image" ]]; then
28 echo "unrecognised option: $1" 1>&2
33 [ "$1" = "-" ] && shift
35 if ! [[ "$size" =~ '^([0-9]*(x[0-9]+)?)$' ]]; then
36 echo "invalid size specification: $size" 1>&2
40 if [[ -z "$1" ]]; then
41 echo "usage: thumbnail.zsh [--small|--size <spec>] [--image] [--music] path" 1>&2
45 if [[ -n "$ismusic" ]]; then
46 imgpath="$MUSIC/$(dirname "${1#$MUSIC}")/cover.jpg"
47 [[ ! -f "$imgpath" ]] && imgpath="${imgpath%jpg}png"
52 [[ ! -f "$imgpath" ]] && exit 0
54 image="$(readlink -f -- "$imgpath")"
55 [[ ! -f "$image" ]] && exit 0
57 thumb="$thumbs/$(echo -n $image | md5sum - | cut -d ' ' -f 1)_$size.png"
58 if [[ -f "$thumb" ]]; then
59 mtime_s="$(stat -c %Y -- "$image")"
60 mtime_t="$(stat -c %Y -- "$thumb")"
61 if [ "$mtime_s" -gt "$mtime_t" ]; then
62 convert -scale "$size" "$image" "$thumb"
65 convert -scale "$size" "$image" "$thumb"
69 [ -n "$printimg" ] && echo "$image"