Converting XCF and other files using command line with GIMP?
Solution 1
I'm a couple of years late, but I thought I'd add what I think is by far the best solution: there is a tool suite called Xcftools (on Ubuntu, apt-get install xcftools
), which has a utility called xcf2png
that does this job perfectly.
xcf2png image.xcf -o image.png
This is much better than a) using ImageMagick (which as I said in a comment above is horribly broken), or b) using Gimp (which has an extremely complicated scripting language for simply exporting an image).
Solution 2
I guess ImageMagick should do what you want (and even more)
convert image.xcf image.png
Solution 3
A very good solution (and explanations!) can be found here. In short, there is a bash script feeding scheme/lisp to gimp
#!/bin/bash
{
cat <<EOF
(define (convert-xcf-to-jpeg filename outfile)
(let* (
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-merge-visible-layers image CLIP-TO-IMAGE)))
)
(file-jpeg-save RUN-NONINTERACTIVE image drawable outfile outfile .9 0 0 0 " " 0 1 0 1)
(gimp-image-delete image) ; ... or the memory will explode
)
)
(gimp-message-set-handler 1) ; Messages to standard output
EOF
for i in *.xcf; do
echo "(gimp-message \"$i\")"
echo "(convert-xcf-to-jpeg \"$i\" \"${i%%.xcf}.jpg\")"
done
echo "(gimp-quit 0)"
} | gimp -i -b -
But look at the page for the full story. It's worth it.
Solution 4
Very few, if any, programs other than GIMP read XCF files. This is by design from the GIMP developers, the format is not really documented or supported as a general-purpose file format.
That being said, look into using GIMP itself, using command line arguments (especially the --batch
option).
EDIT: It looks as if ImageMagick does support XCF, so that is probably an easier route if the support seem so be good enough. I haven't tested it, and the documentation doesn't say much. I would be a bit wary.
Ivan Vučica
Croatian developer, who used to focus on (and still likes) mostly iOS and Mac development. Currently at works for a search engine company. Interests include game and web development, with game development experience on Mac, Windows and GNU/Linux. Currently an SRE at a certain search company.
Updated on June 06, 2022Comments
-
Ivan Vučica almost 2 years
If I have an XCF file (or any other supported by Gimp) how can I convert it to, for example, PNG for display or further processing?
-
Ivan Vučica about 15 yearsLooks like imagemagick's convert works. I would prefer using GIMP since it surely supports its own format better, and also supports other formats. I have tried looking into GIMP from shell but it's a bit unintuitive. Can you perhaps drop an example or two on converting with GIMP,or a link with docs?
-
sam hocevar almost 14 yearsFrom my experience, current versions of ImageMagick have very buggy support for XCF. Various layer sizes cause the resulting image to be completely black. I also experience alpha channel bugs (solid pixels appearing from nowhere).
-
Laurence Gonsalves about 13 yearsYeah, ImageMagick's XCF support is seriously broken. Using gimp itself would be a better option.
-
mgiuca almost 13 yearsThis didn't work for me at all. It seems to be wanting to export layers as separate images (it created a name-0.png, name-1.png, for each layer), but it only extracted the first two layers and changed alpha to binary. So I'd rather use GIMP. Just can't for the life of me figure out what Lisp code to write...
-
brettv about 4 yearsUsing -flatten creates a single image, which solves the problem of ImageMagick saving each layer as an individual image.
-
Keyur Padalia about 3 yearsThis worked well for me until recently. Using xcftools 1.0.7 and Gimp 2.10.22, I get
Warning: XCF version 11 not supported (trying anyway...)
and the output is a fully transparent image. -
xeruf over 2 yearsyep, horribly outdated unfortunately, so ImageMagick it is then