4 thumbs="$HOME/.fvwm/.thumbs"
6 if ! [[ -d "$thumbs" ]]; then
7 mkdir "$thumbs" || exit 1
14 while [[ "${1#--}" != "$1" && "$1" != "-" ]]; do
15 if [[ "$1" == "--small" ]]; then
17 elif [[ "$1" == "--size" ]]; then
20 elif [[ "$1" = "--music" ]]; then
22 elif [[ "$1" = "--image" ]]; then
25 echo "unrecognised option: $1" 1>&2
30 [ "$1" = "-" ] && shift
32 if ! [[ "$size" =~ '^([0-9]*(x[0-9]+)?)$' ]]; then
33 echo "invalid size specification: $size" 1>&2
37 if [[ -z "$1" ]]; then
38 echo "usage: thumbnail.zsh [--small|--size <spec>] [--image] [--music] path" 1>&2
42 if [[ -n "$ismusic" ]]; then
43 imgpath="$music/$(dirname "${1#$music}")/cover.jpg"
44 [[ ! -f "$imgpath" ]] && imgpath="${imgpath%jpg}png"
49 [[ ! -f "$imgpath" ]] && exit 0
51 image="$(readlink -f -- "$imgpath")"
52 [[ ! -f "$image" ]] && exit 0
54 thumb="$thumbs/$(echo -n $image | md5sum - | cut -d ' ' -f 1)_$size.png"
55 if [[ -f "$thumb" ]]; then
56 mtime_s="$(stat -c %Y -- "$image")"
57 mtime_t="$(stat -c %Y -- "$thumb")"
58 if [ "$mtime_s" -gt "$mtime_t" ]; then
59 convert -scale "$size" "$image" "$thumb"
62 convert -scale "$size" "$image" "$thumb"
66 [ -n "$printimg" ] && echo "$image"