-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkfavicon
executable file
·57 lines (47 loc) · 1.49 KB
/
mkfavicon
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# New version, 2018, doesn't do 16 color mode for smaller icons, does
# do larger icons.
usage () {
echo "Usage: mkfavicon input.ext [ favicon.ico ]"
echo ""
echo " Scales input.ext to a variety of square sizes and makes a favicon out"
echo " of them. Without upscaling, tries to make input.ext into 16x16, 32x32,"
echo " 48x48, 64x64, 128x128, and 255x255 images to combine."
exit
}
input="$1"
output="$2"
targets="16 32 48 64 128 255"
tmpfiles=
tmppre=/tmp/favico-$$
case "$input" in
''|-h|--help) usage ;;
*.pgm|*.ppm|*.pam|*.pnm) tool=cat ;;
*.[gG][iI][fF]) tool=giftopnm ;;
*.[pP][nN][gG]) tool=pngtopnm ;;
*.[jJ][pP][gG]|*.[jJ][pP][eE][gG]) tool=djpeg ;;
*) tool=anytopnm ;;
esac
if [ ! -f "$input" ] ; then usage ; fi
if [ -z "$output" ] ; then output=favicon.ico ; fi
$tool "$input" > $tmppre.full
tmpfiles="$tmpfiles $tmppre.full"
usefiles=
# output of pnminfo is eg: ysize 500
size=$(pnminfo -l < $tmppre.full | tr -cd 0-9 )
for out in $targets ; do
if expr $out \< $size > /dev/null ; then
pnmscale -xysize $out $out $tmppre.full | pnmquant 256 > $tmppre.$out 2>/dev/null
tmpfiles="$tmpfiles $tmppre.$out"
usefiles="$usefiles $tmppre.$out"
else
if [ $out = $size ] ; then
pnmquant 256 < $tmppre.full > $tmppre.$out 2>/dev/null
tmpfiles="$tmpfiles $tmppre.$out"
usefiles="$usefiles $tmppre.$out"
fi
fi
done
# ppmtowinicon [-andpgms] [-output output.ico] [ppmfiles...]
ppmtowinicon -output "$output" $usefiles
rm -f $tmpfiles