aboutsummaryrefslogtreecommitdiffstats
path: root/build/image-optimization.sh
blob: bf825c96cc6f55600459c2e7a42a6c9393e21ae4 (plain)
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
#!/usr/bin/env bash

function recursive_optimize_images() {
	cd "$1":

	# Optimize all JPGs and PNGs
	optipng -o6 -strip all *.png;
	jpegoptim --strip-all *.jpg;

	# Optimize all SVGs
	for svg in *.svg;
	do
		mv $svg $svg.opttmp;
		scour --create-groups \
			--enable-id-stripping \
			--enable-comment-stripping \
			--shorten-ids \
			--remove-metadata \
			--strip-xml-prolog \
			--no-line-breaks  \
			-i $svg.opttmp \
			-o $svg;
	done;

	# Remove temporary SVGs
	rm *.opttmp

	# Check all subfolders
	for dir in */
	do
		if [[ -d "$DIR" ]]; then
			recursive_optimize_images "$dir"
			cd ..
		fi
	done;
}

recursive_optimize_images ../