As part of my build process I need to convert a number of XCF (GIMP\'s native format) images into PNG format. I\'m sure this should be possible using GIMP\'s batch mode, but I h
Here is my solution utilizing GIMP, GIMP's python-fu and bash. Note that GIMP's python-fu can only be run under a gimp
process, not under plain python.
#!/bin/bash
set -e
while getopts df: OPTION "$@"; do
case $OPTION in
d)
set -x
;;
f)
XCFFILE=${OPTARG}
;;
esac
done
if [[ -z "$XCFFILE" ]]; then
echo "usage: `basename $0` [-d] -f "
exit 1
fi
# Start gimp with python-fu batch-interpreter
gimp -i --batch-interpreter=python-fu-eval -b - << EOF
import gimpfu
def convert(filename):
img = pdb.gimp_file_load(filename, filename)
new_name = filename.rsplit(".",1)[0] + ".png"
layer = pdb.gimp_image_merge_visible_layers(img, 1)
pdb.gimp_file_save(img, layer, new_name, new_name)
pdb.gimp_image_delete(img)
convert('${XCFFILE}')
pdb.gimp_quit(1)
EOF