imagemagickscript-fuirfanviewxcf

Batch convert from XCF version 11


I have a folder of images saved in .xcf format, and I would like to batch convert them to a more convenient format. I've tried a few approaches that haven't worked:

My last hope is to write a batch convert script that will work in the latest version of Gimp itself, but I don't have any experience with ScriptFu. I found a script that converts some other file types (http://beefchunk.com/documentation/lang/gimp/GIMP-Scripts-Fu.html#convertjpg-script-fu) but don't quite have the knowledge to modify it. Does anybody know the right calls/arguments to read xcf and write png?


Solution

  • Here is a self-contained bash script that should convert all xcf files in your current directory into png format copies. It should work on any Linux computer with Gimp installed. It does not require any installation in script directories:

    #!/bin/bash
    # xcfs2png.sh
    # Invoke The GIMP with Script-Fu convert-xcf-png
    # No error checking.
    {
    cat <<EOF
    (define (convert-xcf-png filename outpath)
        (let* (
                (image (car (gimp-xcf-load RUN-NONINTERACTIVE filename filename )))
                (drawable (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)))
                )
            (begin (display "Exporting ")(display filename)(display " -> ")(display outpath)(newline))
            (file-png-save2 RUN-NONINTERACTIVE image drawable outpath outpath 0 9 0 0 0 0 0 0 0)
            (gimp-image-delete image)
        )
    )
    
    (gimp-message-set-handler 1) ; Messages to standard output
    EOF
    
    for i in *.xcf; do
      echo "(convert-xcf-png \"$i\" \"${i%%.xcf}.png\")"
    done
    
    echo "(gimp-quit 0)"
    
    } | gimp -i -b -
    

    Tested working with Gimp v2.10.18 on Kubuntu 20.04. Thanks to patdavid at pixls.us for the original script.