3 # Copyright © 2008 Nick Bowler
5 # Simple thumbnail generator for use with FVWM. Thumbnails can be generated at
6 # any desired size, and are cached for future use. Prints the cached filename
9 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
10 # This is free software: you are free to do what the fuck you want to.
11 # There is NO WARRANTY, to the extent permitted by law.
13 if [[ -z "$MUSIC" ]]; then
17 thumbs="$HOME/.fvwm/.thumbs"
19 if ! [[ -d "$thumbs" ]]; then
20 mkdir "$thumbs" || exit 1
27 while [[ "${1#--}" != "$1" && "$1" != "-" ]]; do
28 if [[ "$1" == "--small" ]]; then
30 elif [[ "$1" == "--size" ]]; then
33 elif [[ "$1" = "--music" ]]; then
35 elif [[ "$1" = "--image" ]]; then
38 echo "unrecognised option: $1" 1>&2
43 [ "$1" = "-" ] && shift
45 if ! [[ "$size" =~ '^([0-9]*(x[0-9]+)?)$' ]]; then
46 echo "invalid size specification: $size" 1>&2
50 if [[ -z "$1" ]]; then
51 echo "usage: thumbnail.zsh [--small|--size <spec>] [--image] [--music] path" 1>&2
55 if [[ -n "$ismusic" ]]; then
56 imgpath="$MUSIC/$(dirname "${1#$MUSIC}")/cover.jpg"
57 [[ ! -f "$imgpath" ]] && imgpath="${imgpath%jpg}png"
62 [[ ! -f "$imgpath" ]] && exit 0
64 image="$(readlink -f -- "$imgpath")"
65 [[ ! -f "$image" ]] && exit 0
67 thumb="$thumbs/$(echo -n $image | md5sum - | cut -d ' ' -f 1)_$size.png"
68 if [[ -f "$thumb" ]]; then
69 mtime_s="$(stat -c %Y -- "$image")"
70 mtime_t="$(stat -c %Y -- "$thumb")"
71 if [ "$mtime_s" -gt "$mtime_t" ]; then
72 convert -scale "$size" "$image" "$thumb"
75 convert -scale "$size" "$image" "$thumb"
79 [ -n "$printimg" ] && echo "$image"