2021-05-18 04:03:18 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
SRC=../www/img
|
|
|
|
SIZE=500
|
|
|
|
|
|
|
|
# transform path to /img/*/.thumb/
|
|
|
|
pathtrans() {
|
2024-09-27 01:32:04 +00:00
|
|
|
filename=$(basename "${1%.*}")
|
|
|
|
pathname="${1%/*}"
|
|
|
|
if [ ! -d ${pathname}/.thumb ]; then
|
|
|
|
mkdir ${pathname}/.thumb/
|
2021-05-18 04:03:18 +00:00
|
|
|
fi
|
2024-09-27 01:32:04 +00:00
|
|
|
echo "${pathname}/.thumb/${filename}.png"
|
2021-05-18 04:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# generate thumbnails in /img/*/.thumb/
|
|
|
|
resize() {
|
|
|
|
output=$(pathtrans $1)
|
2021-05-21 19:14:27 +00:00
|
|
|
if echo $1 | grep -e .gif -e .zip > /dev/null; then
|
2021-05-18 04:09:25 +00:00
|
|
|
return
|
|
|
|
fi
|
2021-05-18 04:03:18 +00:00
|
|
|
if [ ! -f ${output} ]; then
|
2021-06-15 19:10:49 +00:00
|
|
|
echo "Stripping metadata from $1"
|
2024-09-27 01:32:04 +00:00
|
|
|
convert "$1" -strip "$1"
|
2021-05-21 19:14:27 +00:00
|
|
|
echo "Generating thumbnail for $1"
|
2024-09-27 01:32:04 +00:00
|
|
|
convert "$1" -strip -auto-orient -resize ${SIZE} -dither FloydSteinberg -colors 16 ${output}
|
2021-05-18 04:03:18 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-09-27 01:32:04 +00:00
|
|
|
if [ -z "$1" ]; then
|
2021-05-18 19:10:28 +00:00
|
|
|
echo "usage: $0 [build|clean]"
|
|
|
|
else
|
|
|
|
case $1 in
|
|
|
|
"build")
|
2021-05-21 19:14:27 +00:00
|
|
|
echo "Updating thumbnails cache"
|
2024-09-27 01:32:04 +00:00
|
|
|
for x in $(find ${SRC}/*/*); do resize "$x"; done;;
|
2021-05-18 19:10:28 +00:00
|
|
|
"clean")
|
2021-05-21 19:14:27 +00:00
|
|
|
echo "Cleaning thumbnails cache"
|
2021-05-18 19:10:28 +00:00
|
|
|
rm -rf ${SRC}/*/.thumb
|
2021-05-21 19:14:27 +00:00
|
|
|
echo "Cleaned";;
|
2021-05-18 19:10:28 +00:00
|
|
|
esac
|
|
|
|
fi
|