2022-10-17 00:50:53 +00:00
|
|
|
{ bc, libwebp, scour, writeShellScriptBin }:
|
2022-08-27 03:54:29 +00:00
|
|
|
|
|
|
|
writeShellScriptBin "optimize-images" ''
|
|
|
|
shopt -s globstar nullglob
|
|
|
|
${scour}/bin/scour -i static/image/_favicon.svg -o static/image/favicon.svg
|
|
|
|
for image in content/**/_*.png static/image/**/_*.png; do
|
|
|
|
path=$(dirname $image)
|
2022-10-17 00:50:53 +00:00
|
|
|
file=$(basename -s .png $image)
|
|
|
|
newimage=$path/''${file:1}.webp
|
2022-08-27 03:54:29 +00:00
|
|
|
echo "optimizing $image"
|
2022-10-17 00:50:53 +00:00
|
|
|
${libwebp}/bin/cwebp -quiet -o $newimage $image
|
2022-08-27 03:54:29 +00:00
|
|
|
oldsize=$(stat --format=%s $image)
|
|
|
|
newsize=$(stat --format=%s $newimage)
|
|
|
|
pct=$(${bc}/bin/bc <<< "scale=1; $newsize * 100 / $oldsize")
|
|
|
|
echo "size went from "$(($oldsize / 1024))"KB to "$(($newsize / 1024))"KB ("$pct"% as large as original)"
|
|
|
|
done
|
|
|
|
''
|