-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoptimize_tiles.sh
More file actions
34 lines (29 loc) · 1008 Bytes
/
optimize_tiles.sh
File metadata and controls
34 lines (29 loc) · 1008 Bytes
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
#!/usr/bin/bash
# Usage: optimize_tiles.sh <input_dir> <output_dir>
#
# Read in recursively an input directory of .PNG map tiles, remove 'blank' tiles (tiles less thank 2K in size) and convert
# tile to web-optimized .JPG tiles with ImageMagick. Save optimized tile to to output directory, preservering relative
# directory tree of input directory.
if [ "$#" = 0 ]; then
echo "No arguments given <input_dir> <output_dir>"
exit 1
elif [ "$#" = 1 ]; then
echo "Missing second argument <output_dir>"
exit 1
elif [ "$#" = 2 ]; then
input_dir=$1
output_dir=$2
echo "Starting conversion with input $input_dir and output dir $output_dir"
else
echo "Too many args."
exit 1
fi
files=$(find $input_dir -name "*.png")
find "$input_dir" -type d -print0 | xargs -0 -I {} mkdir -p $output_dir"/{}"
for f in $files
do
echo "$f"
convert -strip -sampling-factor 4:2:0 -define jpeg:dct-method=float -interlace Plane -quality 85% "$f" "$output_dir/${f/%.png/.jpg}"
done
echo "Done."
exit 0