使用 GIMP 命令行转换 XCF 和其他文件?

发布于 2024-07-14 09:25:44 字数 63 浏览 12 评论 0 原文

如果我有 XCF 文件(或 Gimp 支持的任何其他文件),如何将其转换为 PNG 等文件以供显示或进一步处理?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

不奢求什么 2024-07-21 09:25:45

我晚了几年,但我想我应该添加我认为迄今为止最好的解决方案:有一个名为 Xcftools(在 Ubuntu 上,apt-get install xcftools),它有一个名为 xcf2png 的实用程序可以完美地完成这项工作。

xcf2png image.xcf -o image.png

这比a)使用ImageMagick(正如我在上面的评论中所说的那样,它被严重破坏了),或b)使用Gimp(它有一个非常复杂的脚本语言,用于简单地导出图像)要好得多。

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

窗影残 2024-07-21 09:25:45

我想 ImageMagick 应该做你想做的事(甚至更多)

convert image.xcf image.png

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

convert image.xcf image.png
陌伤浅笑 2024-07-21 09:25:45

可以找到一个非常好的解决方案(和解释!) 此处。 简而言之,有一个 bash 脚本向 gimp 提供方案/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 -

,但请查看该页面以了解完整的故事。 这很值得。

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.

影子是时光的心 2024-07-21 09:25:45

除了 GIMP 之外,很少有程序(如果有的话)读取 XCF 文件。 这是 GIMP 开发人员设计的,该格式并未真正记录或支持作为通用文件格式。

话虽这么说,请考虑使用 GIMP 本身,使用命令行参数(尤其是 --batch 选项)。

编辑:看起来好像ImageMagick确实支持XCF,所以这可能是一个更简单的路线如果支持看起来足够好的话。 我没有测试过,文档也没有说太多。 我会有点警惕。

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.

带上头具痛哭 2024-07-21 09:25:45

猛击单线。 只需要转换(通常已经从 imagemagick 安装)。

convert -alpha on -background none -layers merge t2.xcf t2.png

迭代 xcf 文件以将它们转换为适当名称的脚本:

for i in *.xcf; do convert -alpha on -background none -layers merge $i ${i/xcf/png}; done

Bash oneliner. Only needs convert (which usually already installed from imagemagick).

convert -alpha on -background none -layers merge t2.xcf t2.png

Script that iterates over xcf files to convert them with appropriate names:

for i in *.xcf; do convert -alpha on -background none -layers merge $i ${i/xcf/png}; done
短叹 2024-07-21 09:25:45

如果您想将 .xcf 图像批量转换为 .png,您可能会发现此包装脚本更有用:

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

将其保存在 PATH 中的某个位置 xcftopng (注意 to 而不是2) 并像这样调用它:

ls *.xcf|xargs -l xcftopng

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文