all repos — eureka @ 439619fd297237592815b8f6dbc0e6564fd88af0

static site generator based on the 100r.co engine

thumbnailer.sh (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

SRC=../www/img
SIZE=500

# transform path to /img/*/.thumb/
pathtrans() {
  filename=$(echo $1 | awk -F/ '{print $NF}')
  filename=$(echo ${filename} | awk 'BEGIN{FS=OFS="."}{NF--; print $0}')
  transform=$(echo $1 | awk 'BEGIN{FS=OFS="/"}{NF--; print $0}')
  if [ ! -d ${transform}/.thumb ]; then
    mkdir ${transform}/.thumb/
  fi
  transform=${transform}/.thumb/${filename}.png
  echo ${transform}
}

# generate thumbnails in /img/*/.thumb/
resize() {
  output=$(pathtrans $1)
  if echo $1 | grep -e .gif -e .zip > /dev/null; then
    return
  fi
  if [ ! -f ${output} ]; then
    echo "Stripping metadata from $1"
    convert $1 -strip $1
    echo "Generating thumbnail for $1"
    convert $1 -strip -auto-orient -resize ${SIZE} -dither FloydSteinberg -colors 16 ${output}
  fi
}

if [ -z $1 ]; then
  echo "usage: $0 [build|clean]"
else
  case $1 in
    "build")
      echo "Updating thumbnails cache"
      for x in $(find ${SRC}/*/*); do resize $x; done;;
    "clean")
      echo "Cleaning thumbnails cache"
      rm -rf ${SRC}/*/.thumb
      echo "Cleaned";;
  esac
fi