Last active
July 30, 2022 23:58
-
-
Save typebrook/6916fe44750c3b1bc22af413252d19f9 to your computer and use it in GitHub Desktop.
sprite for rudymap #rudymap #sprite #mapbox #icon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/env bash | |
ratio=1 | |
[[ $1 == '--@2x' ]] && decorator=@2x && ratio=2 && shift | |
# Create Sprite JSON file | |
x=0 | |
identify $@ | \ | |
cut -d' ' -f1,3 | \ | |
while read image wh; do | |
width=${wh%x*} | |
height=${wh/*x} | |
file=$(basename $image) | |
echo "\"${file//.*}\":{\"width\":$width,\"height\":$height,\"pixelRatio\":$ratio,\"x\":$x,\"y\":0}" | |
x=$(($x+$width)) | |
done | \ | |
tr '\n' ',' | \ | |
sed -E 's/^/{/; s/,$/}/' | \ | |
jq . >sprite${decorator}.json | |
# Create Sprite PNG file | |
convert +append -background none $@ sprite${decorator}.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.ONESHELL: | |
all: sprite | |
clean: | |
rm *.svg *.json *.png 2>/dev/null | |
svg: | |
while read svg _ _ url; do | |
curl $$url | sed '/stroke="#000000"/d' >$$svg | |
done <svg.list | |
# spritezero should use valid fork, like: | |
# yarn global add @streetcredlabs/spritezero-cli | |
sprite: | |
DIR2x=$$(mktemp -d) | |
DIR=$$(mktemp -d) | |
cat svg.list \ | |
| while read svg width height path; do | |
rsvg-convert $$svg -w $$(($$width*2)) -h $$(($$height*2)) -f svg >$$DIR2x/$$svg.svg | |
rsvg-convert $$svg -w $$width -h $$height -f svg >$$DIR/$$svg | |
# Some svg files cannot display correctly after the first convert, so we do the second! | |
#rsvg-convert $$svg -w $$width -h $$height -f svg >resized.svg && mv resized.svg $$svg | |
done | |
./create_sprite.sh --@2x $$(find $$DIR2x -type f) | |
./create_sprite.sh $$(find $$DIR -type f) | |
#spritezero sprite@2x $$DIR2x | |
#spritezero sprite $$DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s_camp_site.svg 16 16 https://raw.githubusercontent.com/alpha-rudy/taiwan-topo/master/styles/mapsforge_style/moiosm_res/s_camp_site.svg | |
mountain.svg 32 32 https://www.svgrepo.com/download/318070/places-mountains.svg | |
trig.svg 32 32 https://raw.githubusercontent.com/alpha-rudy/taiwan-topo/master/styles/mapsforge_style/moiosm_res/s_sp_trig.svg | |
trig_forest.svg 32 32 https://raw.githubusercontent.com/alpha-rudy/taiwan-topo/master/styles/mapsforge_style/moiosm_res/s_sp_forest_trig.svg | |
trig_c.svg 32 32 https://raw.githubusercontent.com/alpha-rudy/taiwan-topo/master/styles/mapsforge_style/moiosm_res/s_sp_trig_C.svg | |
shield_motorway.svg 32 32 https://upload.wikimedia.org/wikipedia/commons/d/d3/TWHW.svg | |
shield_primary.svg 32 32 https://upload.wikimedia.org/wikipedia/commons/b/b7/TW_PHW.svg | |
shield_secondary.svg 32 32 https://www.svgrepo.com/download/342778/rectangle.svg | |
shield_tertiary.svg 32 32 https://www.svgrepo.com/download/342778/rectangle.svg | |
skull.svg 32 32 https://upload.wikimedia.org/wikipedia/commons/1/1c/Skull_%26_crossbones.svg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment