visual/thumbs.sh (view raw)
1#!/bin/sh -ex
2
3_img_dirs="$( find . -maxdepth 1 -type d | sed -e '1d' -e 's/^\.\///' )"
4_thumb_size="835x"
5_thumbs_dir="thumbs"
6_force_render=0
7
8usage() {
9 echo "usage: $0 [-f|--force]"
10}
11
12[ -n "$1" ] && \
13 case $1 in
14 -f|--force)
15 _force_render=1
16 ;;
17 -h|--help)
18 usage
19 exit 0
20 ;;
21 *)
22 usage
23 exit 1
24 ;;
25 esac
26
27for dir in $_img_dirs
28do
29 cd "./$dir" || exit 1
30
31 mkdir -p "$_thumbs_dir"
32
33 _imgs="$(find . -maxdepth 1 \
34 -iname "*.jpg" -or \
35 -iname "*.jpeg" -or \
36 -iname "*.gif" -or \
37 -iname "*.png" -type f | cut -b 3-)"
38 for _img in $_imgs
39 do
40 _ext="${_img##*.}"
41 _name="${_img%%.*}"
42 _thumb="./$_thumbs_dir/${_name}_thumb.${_ext}"
43
44 [ "$_force_render" -eq 1 ] || [ ! -f "$_thumb" ] && \
45 {
46 # when compressed, gifs look ugly, so just copy them
47 # i know this is bad, but i'll adress it later
48 [ "$_ext" = "gif" ] && \
49 echo "copied $1 to $_thumb" && \
50 cp "$_img" "$_thumb" && continue
51
52 echo "creating thumbnail for $_name..."
53 convert "$_img" -resize "$_thumb_size" "$_thumb"
54 }
55 done
56
57 cd ".."
58
59done
60