2021-05-18 04:03:18 +00:00
|
|
|
#!/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)
|
2021-05-18 04:09:25 +00:00
|
|
|
if echo $1 | grep .gif > /dev/null; then
|
|
|
|
return
|
|
|
|
fi
|
2021-05-18 04:03:18 +00:00
|
|
|
if [ ! -f ${output} ]; then
|
2021-05-18 04:09:25 +00:00
|
|
|
echo "generating thumbnail for $1"
|
2021-05-18 04:03:18 +00:00
|
|
|
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}'")
|
|
|
|
|
2021-05-18 04:09:25 +00:00
|
|
|
echo -n "modifying html to use thumbnail for $1"
|
2021-05-18 04:03:18 +00:00
|
|
|
for f in $(find ${ROOT}/*.html); do
|
2021-05-18 04:09:25 +00:00
|
|
|
echo -n "."
|
|
|
|
if grep ${src} ${f} > /dev/null; then
|
2021-05-18 04:03:18 +00:00
|
|
|
sed -i s#${src}#${dest}# $f
|
|
|
|
fi
|
|
|
|
done
|
2021-05-18 04:09:25 +00:00
|
|
|
echo
|
2021-05-18 04:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo "creating new thumbnails"
|
|
|
|
for x in $(find ${SRC}/*/*); do resize $x exit; done
|
|
|
|
echo "done"
|