Requirements
On a UNIX-like operating system (Linux, MacOS, etc.), download and install the following:
- ImageMagick
- rsvg-convert
- pngquant
Script
Save the following as build.sh
:
#!/bin/bash
# Relative path to location of SVG file to make into ICO file.
ICON_PATH=../../images/edible.svg
ICON_BASE=$(basename "$ICON_PATH")
ICON_DIR=$(dirname "$ICON_PATH")
ICON_FILE="${ICON_BASE%*.}"
ICON_EXT="${ICON_BASE##*.}"
FAVICON_FILE=favicon
FAVICON_EXT=.ico
# This uses rsvg-convert to create crisp PNG icons.
for size in 16 32 64 128 150 192 512; do
ICON_OUT=$ICON_FILE-${size}.png
DIMENSIONS=${size}x${size}
rsvg-convert -w $size -p 300 -d 300 $ICON_PATH > $ICON_OUT
# Use ImageMagick to center the image and make it square.
convert $ICON_OUT -gravity center -background transparent \
-resize $DIMENSIONS -extent $DIMENSIONS temp-$ICON_OUT
# Use 8-bit colour to reduce the file size.
pngquant 256 < temp-$ICON_OUT > $FAVICON_FILE-$DIMENSIONS.png
done
# Merge the 16- and 32-pixel versions into a multi-sized ICO file.
convert \
$FAVICON_FILE-16x16.png \
$FAVICON_FILE-32x32.png \
-colors 256 ../$FAVICON_FILE$FAVICON_EXT
# Create Android icons.
mv $FAVICON_FILE-192x192.png android-chrome-192x192.png
mv $FAVICON_FILE-512x512.png android-chrome-512x512.png
# Create MS tile icon.
mv $FAVICON_FILE-150x150.png mstile-150x150.png
# Clean up the temporary files.
rm ${ICON_FILE}*png temp-${ICON_FILE}*png
Edit the file and change the ICON_PATH
variable to the location of the SVG file to convert, such as:
ICON_PATH=../images/favicons/procensus.svg
Run the script:
./build.sh
Various icons are created in the current directory.
Note: Be sure to backup your files before running this command as it will erase the PNG files it creates while processing.
Browser Config
Save the following file as browserconfig.xml
:
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#da532c</TileColor>
</tile>
</msapplication>
</browserconfig>
convert -density xyz image.svg ...
– Nonjurorsudo apt install librsvg2-bin
– Eugenieeugenio