-
Notifications
You must be signed in to change notification settings - Fork 18
/
build-images
executable file
·58 lines (47 loc) · 1.41 KB
/
build-images
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
#!/usr/bin/env zsh
export PATH=.venv/bin:$PATH
# https://github.com/Kozea/CairoSVG/issues/392
# To make CairoSVG work with Homebrew-installed cairo, you need to set the DYLD_LIBRARY_PATH environment variable.
export DYLD_LIBRARY_PATH="/opt/homebrew/opt/cairo/lib:$DYLD_LIBRARY_PATH"
# Builds individual svg, uncompressed png, and quantized png images.
cmds=( 'cairosvg' 'imagemin' 'pngquant' 'xmllint')
for cmd in "${cmds[@]}"; do
if ! type "$cmd" > /dev/null; then
echo "Please install the command '$cmd' to build patterns"
exit 1
fi
done
svgdir=assets/svg
outdir=assets/png
pdir=${outdir}-uncompressed
mkdir -p $outdir $pdir
for f in $svgdir/*.svg; do
fn=${f:t:r}.png
out=${pdir}/${fn}
quant=$outdir/$fn
# Pretty-print xml and save old version in case of errors
oldf=$f.dirty
mv $f $oldf
cat $oldf | xmllint --format - > $f
if cmp $f $oldf >/dev/null 2>&1
then
rm -f $oldf
# Don't rebuild PNGs if they already exist
[[ -f $out && -f $quant ]] && continue
else
echo "Reformatted svg $f"
fi
# Build pngs
cairosvg -f png -s 16 $f > $out
ls -hs $out
# Build paletted pngs for smaller file size
cat $out | imagemin --plugin=pngquant > $quant
ls -hs $quant
# Display image if we have a fancy terminal
if type "imgcat" > /dev/null; then
# Install with `npm install -g imgcat-cli` for now
imgcat --width 100px $out
fi
echo ""
done
rm -f $svgdir/*.svg.dirty