add thumbnailer

This commit is contained in:
Iris Lightshard 2021-05-17 22:03:18 -06:00
parent 89ef84cdbc
commit 7e7c2f8003
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
2 changed files with 49 additions and 0 deletions

View file

@ -27,6 +27,8 @@ cc -std=c89 -DDEBUG -Wall -Wno-unknown-pragmas -Wpedantic -Wshadow -Wuninitializ
# Run # Run
./main ./main
./thumbnailer.sh
# Cleanup # Cleanup
rm -f ./main rm -f ./main

47
thumbnailer.sh Executable file
View file

@ -0,0 +1,47 @@
#!/bin/sh
ROOT=../www
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 [ ! -f ${output} ]; then
convert $1 -strip -auto-orient -resize ${SIZE} -dither FloydSteinberg -colors 16 ${output}
fi
replace $1 ${output}
}
# crawl through html and replace src='/img/*/*' with src='/img/*/.thumb/*'
replace() {
src=$(echo $1 | sed s#\.\./www##)
dest=$(echo $2 | sed s#\.\./www##)
src=$(echo "src='${src}'")
dest=$(echo "src='${dest}'")
for f in $(find ${ROOT}/*.html); do
if grep ${src} ${f}; then
sed -i s#${src}#${dest}# $f
fi
done
}
echo "creating new thumbnails"
for x in $(find ${SRC}/*/*); do resize $x exit; done
echo "done"