t-r.de/utils/favicon-from-svg.sh
2025-02-14 12:01:46 +01:00

37 lines
884 B
Bash
Executable File

#!/bin/bash
# Source: https://gessel.blackrosetech.com/2020/12/21/favicon-generation-script
# this makes the output verbose
set -ex
# collect the file name you entered on the command line (file.svg)
svg=$1
# set the sizes to be generated (plus 310x150 for msft)
size=(16 32 48 70 76 120 128 150 152 167 180 192 310 512)
# set the write director as a favicon directory below current
out="$(pwd)"
out+="/favicon"
mkdir -p $out
echo Making bitmaps from your svg...
for i in ${size[@]}; do
inkscape -o "$out/favicon-$i.png" -w $i -h $i $svg
done
# Microsoft wide icon (annoying, probably going away)
inkscape -o "$out/favicon-310x150.png" -w 310 -h 150 $svg
echo Compressing...
for f in $out/*.png; do pngquant -f --ext .png "$f" --posterize 4 --speed 1 ; done;
echo Creating favicon
convert $out/favicon-512.png -define icon:auto-resize=48,32,16 $out/favicon.ico
echo Done