Converting XCF and other files using command line with GIMP?

谁说我不能喝 提交于 2019-12-03 12:08:34

问题


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?


回答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).




回答2:


I guess ImageMagick should do what you want (and even more)

convert image.xcf image.png



回答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.




回答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.




回答5:


If you want to bulk convert .xcf images to .png, you might find this wrapper script more useful:

#! /bin/bash -peux
exec xcf2png $1 -o ${1%.xcf}.png

Save it somewhere on your PATH as xcftopng (note the to instead of 2) and call it like so:

ls *.xcf|xargs -l xcftopng


来源:https://stackoverflow.com/questions/630405/converting-xcf-and-other-files-using-command-line-with-gimp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!