Last active
March 10, 2022 10:05
-
-
Save iskolbin/2492653a48fc7a8f8c1f8a5eaf159eb7 to your computer and use it in GitHub Desktop.
Unpack TexturePacker JSON into images
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/bash | |
if [ -z $1 ]; then | |
echo "Usage:\n sh crop_atlas.sh <ATLAS>.json" | |
exit 1 | |
fi | |
IMG=$(cat $1 | jq -j ".meta.image") | |
KEYS=$(cat $1 | jq -j --unbuffered '.frames|keys|join(" ")') | |
EXT="${IMG##*.}" | |
NAME="${IMG%.*}" | |
mkdir -p ${NAME} | |
mkdir -p ${NAME} | |
for F in $(cat $1 | jq -r ".frames|to_entries|.[]|.key" | rev | cut -d'/' -f2- | rev); do | |
mkdir -p ${NAME}/$F | |
done | |
for s in $(cat $1 | jq -j --unbuffered ".frames|to_entries|.[] | select(.value.rotated == false) | \"${NAME}/\",.key,\".${EXT}\n\""); do mkdir -p "$(dirname $s)"; done | |
cat $1 | jq -j --unbuffered ".frames|to_entries|.[] | select(.value.rotated == false) | \"convert $IMG -background none -crop \",.value.frame.w,\"x\",.value.frame.h,\"+\",.value.frame.x,\"+\",.value.frame.y, \" -extent \",.value.sourceSize.w,\"x\",.value.sourceSize.h,\"-\",.value.spriteSourceSize.x,\"-\",.value.spriteSourceSize.y, \" ${NAME}/\",.key,\".${EXT} \n\"" | bash | |
cat $1 | jq -j --unbuffered ".frames|to_entries|.[] | select(.value.rotated == true) | \"convert $IMG -background none -crop \",.value.frame.h,\"x\",.value.frame.w,\"+\",.value.frame.x,\"+\",.value.frame.y, \" -rotate -90 -extent \",.value.sourceSize.w,\"x\",.value.sourceSize.h,\"-\",.value.spriteSourceSize.x,\"-\",.value.spriteSourceSize.y, \" ${NAME}/\",.key,\".${EXT} \n\"" | bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment