66 lines
1.6 KiB
Bash
Executable file
66 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# Did we get an image to convert?
|
|
if [[ ! -f "$1" ]]; then
|
|
echo Usage: $0 [gimpPic.xcf] {anythingToPreview}
|
|
exit 1
|
|
fi
|
|
|
|
# Find information about the image
|
|
IMAGE=$(realpath "$1")
|
|
FILENAME=$(basename "${IMAGE}")
|
|
DIRNAME=$(dirname "${IMAGE}")
|
|
NAME=$(basename "$1" .xcf)
|
|
|
|
# Is it really an XCF?
|
|
file "${IMAGE}" | grep -q "GIMP XCF"
|
|
if [[ "$?" -ne "0" ]]; then
|
|
echo ${FILENAME} is not a GIMP XCF image! >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Switch to folder where the image exists
|
|
pusd "${DIRNAME}" &> /dev/null
|
|
|
|
# Run our Script-Fu to convert each layer to a PNG
|
|
gimp -i -d -f -s -c -b "(script-fu-export-joeylib \"${IMAGE}\")" -b "(gimp-quit 0)" &> /dev/null
|
|
|
|
# Count the PNGs we found
|
|
COUNT=$(find . -maxdepth 1 -name "${FILENAME}-DoNtEvErDoThIs-*.png" -printf '.' | wc -m)
|
|
|
|
# Did nothing come back out?
|
|
if [[ "${COUNT}" -eq "0" ]]; then
|
|
echo Unable to extract layers from ${FILENAME}! >&2
|
|
exit 1
|
|
fi
|
|
|
|
# We only do the first two layers. If there's more, warn them.
|
|
if [[ "${COUNT}" -gt "2" ]]; then
|
|
echo ${COUNT} layers found. Only the first two will be used.
|
|
fi
|
|
|
|
# If there's no data dir, make one and remove it later.
|
|
if [[ -d data ]]; then
|
|
HASDATA=1
|
|
else
|
|
HASDATA=0
|
|
mkdir -p data
|
|
fi
|
|
|
|
# Call custom converter
|
|
${JOEY}/utils/imgconvert "${FILENAME}-DoNtEvErDoThIs-1.png" "${FILENAME}-DoNtEvErDoThIs-2.png" "${NAME}"
|
|
mv "data/${NAME}.img" .
|
|
|
|
# Remove data folder if we created one
|
|
if [[ "${HASDATA}" -eq "0" ]]; then
|
|
rm -rf data
|
|
fi
|
|
|
|
# Clean up temp PNG files
|
|
find . -maxdepth 1 -type f -name "${FILENAME}-DoNtEvErDoThIs-*.png" -exec rm -f {} \;
|
|
|
|
# Clean up JLSTATS
|
|
rm -f JLSTATS
|
|
|
|
# Back to our original directory
|
|
popd &> /dev/null
|