-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimised-favicon-generator.sh
35 lines (28 loc) · 1.4 KB
/
optimised-favicon-generator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#! /usr/local/bin/bash
if [ $# -eq 0 ]
then
echo "Usage: "$0" input_favicon.svg"
exit 1;
fi
SVG_SOURCE="$(echo $1)"
OUTPUT_DIR="$(echo `pwd`)"/output
# create the output directory and don't output error if it already exists
mkdir ${OUTPUT_DIR} 2> /dev/null
# generate optimised SVG
scour ${SVG_SOURCE} "${OUTPUT_DIR}"/icon.svg --enable-viewboxing --enable-id-stripping \
--enable-comment-stripping --shorten-ids --indent=none
# generate PNGs
inkscape -h 32 ${SVG_SOURCE} --export-filename "${OUTPUT_DIR}""/favicon_unoptimised.png"
inkscape -h 180 ${SVG_SOURCE} --export-filename "${OUTPUT_DIR}""/apple-touch-icon_unoptimised.png"
inkscape -h 192 ${SVG_SOURCE} --export-filename "${OUTPUT_DIR}""/icon-192_unoptimised.png"
inkscape -h 512 ${SVG_SOURCE} --export-filename "${OUTPUT_DIR}""/icon-512_unoptimised.png"
# optimise PNGs
optipng -o7 -out "${OUTPUT_DIR}"/favicon.ico "${OUTPUT_DIR}""/favicon_unoptimised.png"
optipng -o7 -out "${OUTPUT_DIR}""/apple-touch-icon.png" "${OUTPUT_DIR}""/apple-touch-icon_unoptimised.png"
optipng -o7 -out "${OUTPUT_DIR}""/icon-192.png" "${OUTPUT_DIR}""/icon-192_unoptimised.png"
optipng -o7 -out "${OUTPUT_DIR}""/icon-512.png" "${OUTPUT_DIR}""/icon-512_unoptimised.png"
# clean up temporary files
rm "${OUTPUT_DIR}""/favicon_unoptimised.png"
rm "${OUTPUT_DIR}""/apple-touch-icon_unoptimised.png"
rm "${OUTPUT_DIR}""/icon-192_unoptimised.png"
rm "${OUTPUT_DIR}""/icon-512_unoptimised.png"