all repos — aaoth.xyz @ 324991d82ef26798ed5842a6fe03eabc798ff497

aaoth.xyz website

art/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    [ -d "$_thumbs_dir" ] || mkdir "$_thumbs_dir"
32
33    _imgs="$(find . -maxdepth 1 -type f | cut -b 3-)"
34    for _img in $_imgs
35    do
36        _ext="${_img##*.}"
37        _name="${_img%%.*}"
38        _thumb="./$_thumbs_dir/${_name}_thumb.${_ext}"
39
40        [ "$_force_render" -eq 1 ] || [ ! -f "$_thumb" ] && \
41        {
42            # when compressed, gifs look ugly, so just copy them
43            # i know this is bad, but i'll adress it later
44            [ "$_ext" = "gif" ] && \
45                echo "copied $1 to $_thumb" && \
46                cp "$_img" "$_thumb" && continue
47
48            echo "creating thumbnail for $_name..."
49            convert "$_img" -resize "$_thumb_size" "$_thumb"
50        }
51    done
52
53    cd ".."
54
55done
56