Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
script to convert an ORA file from Krita to PNGs
#!/bin/bash
# painting2sprites - A simple script to read an ORA, resize and trim output PNGs.
INPUT_FILE=$1
OUTPUT_DIR=$2
RESIZE_SCALE="25%"
if [ "$2" == "" ]; then
echo "Usage: $0 <input_ora> <output_dir>"
exit 1
fi
if [ ! -r $INPUT_FILE ]; then
echo "unable to open input file '$INPUT_FILE'"
exit 2
fi
if [ ! -d $OUTPUT_DIR ]; then
echo "output dir doesn't exist or is not a directory"
exit 2
fi
# create a temporary folder
TMP_DIR=`mktemp -d`
echo "Extracting layer data..."
# extra the contents of the ORA file
# ORA is just a ZIP, woo!
unzip -q $INPUT_FILE -d $TMP_DIR
# read layer information from the stack.xml file.
LAYER_NODES=`grep "layer" $TMP_DIR/stack.xml | grep -v hidden`
# go through the visible layer nodes
IFS=$'\n'
for LAYER_NODE in $LAYER_NODES; do
# get the name and filename
LAYER_NAME=`echo $LAYER_NODE | sed "s/^.*name=\"//" | sed "s/\".*$//"`
LAYER_FILE=`echo $LAYER_NODE | sed "s/^.*src=\"//" | sed "s/\".*$//"`
# skip the background layer.
if [ "$LAYER_NAME" == "background" ]; then
continue
fi
# munge the layer name into the filename.
OUT_FILE=`echo "$LAYER_NAME" | sed "s/ /_/g" | tr "A-Z" "a-z"`
echo "exporting layer '$LAYER_NAME' to file '${OUT_FILE}.png'"
# auto-crop: use 'trim' to remove excess transparent border (Krita already mostly does this)
# resize: scale down 4x to get reasonable game-sized assets.
convert "$TMP_DIR/$LAYER_FILE" -trim -resize "$RESIZE_SCALE" "$OUTPUT_DIR/${OUT_FILE}.png"
done
unset IFS
# clean up
rm -rf $TMP_DIR
exit 0
@satishgoda

This comment has been minimized.

Copy link

commented Apr 18, 2017

Works like a charm. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.