Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vladyslav-dotsenko/1960d07bbae6d44692a9d5ae75121a45 to your computer and use it in GitHub Desktop.
Save vladyslav-dotsenko/1960d07bbae6d44692a9d5ae75121a45 to your computer and use it in GitHub Desktop.
GIMP export_layers.sh
#!/bin/bash
# Check if the input file is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <input-file.xcf>"
exit 1
fi
# Input XCF file
input_file="$1"
output_dir="./exported_layers"
# Create output directory if it doesn't exist
mkdir -p "$output_dir"
# GIMP script to export layers
gimp -i -b - <<EOF
(let* (
(image (car (gimp-file-load RUN-NONINTERACTIVE "$input_file" "$input_file")))
(num-layers (car (gimp-image-get-layers image)))
(layers (cadr (gimp-image-get-layers image)))
(layer 0)
)
(while (< layer num-layers)
(let* (
(current-layer (vector-ref layers layer))
(layer-name (car (gimp-item-get-name current-layer)))
(output-file (string-append "$output_dir/" layer-name ".png"))
)
(gimp-file-save RUN-NONINTERACTIVE image current-layer output-file output-file)
(gimp-image-remove-layer image current-layer)
)
(set! layer (+ layer 1))
)
(gimp-quit 0)
)
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment