forked from mapbox/maki
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrender.sh
executable file
·83 lines (68 loc) · 2.15 KB
/
render.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -e -u
# Usage:
# ./render.sh [png|sprite|css|csv]
# Config
tilex=15 # how many icons wide the sprites will be
svgdir="src" # SVGs should already be here
pngdir="renders" # PNGs will be created, possibly overwritten, here
function build_pngs {
# Takes a list of SVG files and renders both 1x and 2x scale PNGs
for svg in $@; do
icon=$(basename $svg .svg)
inkscape \
--export-dpi=90 \
--export-png=${pngdir}/${icon}.png \
$svg > /dev/null
inkscape \
--export-dpi=180 \
--export-png=${pngdir}/${icon}@2x.png \
$svg > /dev/null
done
}
function build_csv {
# Outputs a simple CSV that can be used in Mapnik/TileMill/etc to
# test all of the icons on a map. Example CartoCSS:
# marker-file: url("/path/to/maki/src/[icon]-[size].svg");
# marker-allow-overlap: true;
count=-179
echo "icon,size,x,y" > maki.csv
for icon in $@; do
echo $icon,12,$count,1 >> maki.csv
echo $icon,18,$count,2 >> maki.csv
echo $icon,24,$count,3 >> maki.csv
count=$(($count+1))
done
}
# Get a list of all the icon names - any icons not in maki.json
# will not be rendered or included in the sprites.
icons=$(grep '"icon":' www/maki.json \
| sed 's/.*\:\ "\([-a-z0-9]*\)".*/\1/' \
| tr '\n' ' ')
# Build lists of all the SVG and PNG files from the icons list
svgs=$(for icon in $icons; do echo -n $svgdir/${icon}-{24,18,12}.svg" "; done)
pngs=$(for icon in $icons; do echo -n $pngdir/${icon}-{24,18,12}.png" "; done)
pngs2x=$(for icon in $icons; do echo -n $pngdir/${icon}-{24,18,12}@2x.png" "; done)
case $@ in
png | pngs )
build_pngs $svgs
;;
csv )
build_csv $icons
;;
debug )
# Prints out all of the icon and file lists for debugging
echo -e "\nIcons:"
echo $icons
echo -e "\nSVGs:"
echo $svgs
echo -e "\nPNGs:"
echo $pngs
echo -e "\nPNGs @2x:"
echo $pngs2x
;;
* )
# By default we build the PNGs, but not the CSV or debug output
build_pngs $svgs
;;
esac