bash 使用命令行和 GIMP 转换 XCF 和其他文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/630405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Converting XCF and other files using command line with GIMP?
提问by Ivan Vu?ica
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?
如果我有 XCF 文件(或 Gimp 支持的任何其他文件),我如何将其转换为例如 PNG 以进行显示或进一步处理?
回答by mgiuca
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 xcf2pngthat does this job perfectly.
我迟到了几年,但我想我会添加我认为迄今为止最好的解决方案:有一个名为Xcftools的工具套件(在 Ubuntu 上apt-get install xcftools),它有一个名为的实用程序xcf2png,可以完美地完成这项工作。
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).
这比 a) 使用 ImageMagick(正如我在上面的评论中所说的非常糟糕)或 b) 使用 Gimp(它具有极其复杂的脚本语言,用于简单地导出图像)要好得多。
回答by jassuncao
I guess ImageMagickshould do what you want (and even more)
我想ImageMagick应该做你想做的(甚至更多)
convert image.xcf image.png
回答by Dirk
A very good solution (and explanations!) can be found here. In short, there is a bash script feeding scheme/lisp to gimp
一个很好的解决方案(和解释!)可以在这里找到。简而言之,有一个用于 gimp 的 bash 脚本馈送方案/lisp
#!/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.
但是请查看完整故事的页面。这很值得。
回答by unwind
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.
除了 GIMP 之外,很少有程序会读取 XCF 文件。这是 GIMP 开发人员的设计,该格式并未真正记录或支持为通用文件格式。
That being said, look into using GIMP itself, using command line arguments (especially the --batchoption).
话虽如此,请考虑使用 GIMP 本身,使用命令行参数(尤其是--batch选项)。
EDIT: It looksas 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.
编辑:看起来ImageMagick 确实支持 XCF,所以如果支持看起来足够好,这可能是一条更简单的路线。我还没有测试过,文档也没有说太多。我会有点警惕。
回答by Robin Green
If you want to bulk convert .xcf images to .png, you might find this wrapper script more useful:
如果您想将 .xcf 图像批量转换为 .png,您可能会发现此包装脚本更有用:
#! /bin/bash -peux
exec xcf2png -o ${1%.xcf}.png
Save it somewhere on your PATH as xcftopng(note the toinstead of 2) and call it like so:
将它保存在 PATH 中的某个位置xcftopng(注意to代替2)并像这样调用它:
ls *.xcf|xargs -l xcftopng

