diff options
author | Markus Koch <markus@notsyncing.net> | 2020-04-14 18:10:19 +0200 |
---|---|---|
committer | Markus Koch <markus@notsyncing.net> | 2020-04-14 18:10:19 +0200 |
commit | be1dc049d63dccd22b60e64a2cf1f27a464b5ee4 (patch) | |
tree | 751a45b6f35850cab51d98be209222a8e5921ba0 /scripts/convert_maps.sh | |
download | lifomapserver-be1dc049d63dccd22b60e64a2cf1f27a464b5ee4.tar.gz lifomapserver-be1dc049d63dccd22b60e64a2cf1f27a464b5ee4.tar.bz2 lifomapserver-be1dc049d63dccd22b60e64a2cf1f27a464b5ee4.zip |
Initial commit
Diffstat (limited to 'scripts/convert_maps.sh')
-rwxr-xr-x | scripts/convert_maps.sh | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/convert_maps.sh b/scripts/convert_maps.sh new file mode 100755 index 0000000..32ef029 --- /dev/null +++ b/scripts/convert_maps.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Convert a huge .png file into smaller chunks for LeafletJS. +# +# Copyright (C) 2020 Markus Koch <markus@notsyncing.net> +# +# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +# You can obtain a copy of the license at https://mozilla.org/MPL/2.0/. + +# TODO: The width of the input png has to be a multiple of TILESIZE, otherwise bad things will happen. +# Workaround for now is to add white borders on the bottom and right: +# `convert $MAPFILE -extent ${crop}x${crop} -gravity NorthWest $MAPFILE.scaled.png` + +TILESIZE=256 +MAPNAME="world-2020-04-09" +MAPFILE="../$MAPNAME.png" + +width=`file "$MAPFILE" | sed -n "s/.* \([0-9]\+\) x \([0-9]\+\).*/\1/p"` +crop=$TILESIZE +zoom=0 + +while true; do + out="$MAPNAME/$zoom" + tempfile=$out/temp.png + + echo "" + echo "Generating maps for zoomlevel $zoom to $out..." + + mkdir -p $out; + + if [ ! -f "$tempfile" ]; then + if [ $crop -ge $width ]; then + echo " Reached max zoom at zoomlevel $zoom [using original zoom]" + cp $MAPFILE $tempfile + #convert $MAPFILE -extent ${crop}x${crop} -gravity NorthWest $tempfile + else + echo " Scaling map for zoomlevel $zoom" + convert $MAPFILE -resize ${crop}x${crop} $tempfile + fi + else + echo " Reusing existing scaled image" + fi + + echo " Generating tiles..." + convert $tempfile -crop ${TILESIZE}x${TILESIZE} +adjoin $out/%05d.png + + rm $tempfile + + if [ $crop -ge $width ]; then + break; + fi + crop=$(($crop * 2)) + zoom=$(($zoom + 1)) +done; |