如何正确使用Python中的file_raw_save(GIMP PDB过程)

huangapple go评论61阅读模式
英文:

How to properly use file_raw_save via Python (GIMP PDB Procedure)

问题

以下是您提供的代码部分的翻译:

Plugin code:

def save_aci(save_img, filename):
    img = save_img
    filename = filename.strip()
    pdb.file_raw_save(img, img.layers[0], filename, filename)

register(
    "python_fu_save_aci",
    "导出到ACI文件",
    "将图像导出到ACI文件,如果存在LOD,则包含LOD",
    "作者",
    "作者",
    "2023",
    "保存ACI文件",
    "GRAYA",  # 目前仅支持从灰度图像(带有alpha通道)导出到(RG_88).aci格式
    [
        (PF_IMAGE, "save_img", "要保存的图像", None),
        (PF_FILE, "filename", "完整文件名", None),
    ],
    [],
    save_aci, menu="<Image>/File/")

main()

运行GIMP插件时的输出:

/home/astro/.gimp-2.8/plug-ins/testplugin.py: 致命错误: 分段错误
^C/usr/lib64/gimp/2.0/plug-ins/script-fu 已终止: 中断
gimp: 已终止: 中断
/home/astro/.gimp-2.8/plug-ins/testplugin.py 已终止: 中断
/home/astro/.gimp-2.8/plug-ins/testplugin.py 已终止: 中断
[astro@cobalt-vm plug-ins]$ gimp
跟踪回溯(最近的调用最先):
  File "/usr/lib64/gimp/2.0/python/gimpfu.py", line 736, in response
    dialog.res = run_script(params)
  File "/usr/lib64/gimp/2.0/python/gimpfu.py", line 361, in run_script
    return apply(function, params)
  File "/home/astro/.gimp-2.8/plug-ins/testplugin.py", line 128, in save_aci
    pdb.file_raw_save(img, img.layers[0], filename, filename)
RuntimeError: 调用错误

请注意,这仅是提供给您的代码和输出的翻译,没有包含其他额外的内容。如果您需要任何其他帮助或建议,请随时提出。

英文:

While writing a GIMP 2.0 plugin via Python and gimpfu, I've run into pdb procedures such as file_raw_save(...). There arguments are laid out in the GIMP Procedure Browser (Help-&gt;Procedure Browser). But when calling them I receive very unhelpful output. My code and output is as follows:

Plugin code:

def save_aci(save_img, filename):
    img = save_img
    filename = filename.strip()
    pdb.file_raw_save(img, img.layers[0], filename, filename)

register(
    &quot;python_fu_save_aci&quot;,
    &quot;Exports to ACI file&quot;,
    &quot;Exports image to ACI file, with LODs if they are present&quot;,
    &quot;Author&quot;,
    &quot;Author&quot;,
    &quot;2023&quot;,
    &quot;Save ACI File&quot;,
    &quot;GRAYA&quot;,      # Currently only support export from Grayscale image (with alpha) to (RG_88) .aci format
    [
        (PF_IMAGE, &quot;save_img&quot;, &quot;Image to Save&quot;, None),
        (PF_FILE, &quot;filename&quot;, &quot;Filename Fullpath&quot;, None),
    ],
    [],
    save_aci, menu=&quot;&lt;Image&gt;/File/&quot;)

main()

Output when running GIMP plugin:

/home/astro/.gimp-2.8/plug-ins/testplugin.py: fatal error: Segmentation fault
^C/usr/lib64/gimp/2.0/plug-ins/script-fu terminated: Interrupt
gimp: terminated: Interrupt
/home/astro/.gimp-2.8/plug-ins/testplugin.py terminated: Interrupt
/home/astro/.gimp-2.8/plug-ins/testplugin.py terminated: Interrupt
[astro@cobalt-vm plug-ins]$ gimp
Traceback (most recent call last):
  File &quot;/usr/lib64/gimp/2.0/python/gimpfu.py&quot;, line 736, in response
    dialog.res = run_script(params)
  File &quot;/usr/lib64/gimp/2.0/python/gimpfu.py&quot;, line 361, in run_script
    return apply(function, params)
  File &quot;/home/astro/.gimp-2.8/plug-ins/testplugin.py&quot;, line 128, in save_aci
    pdb.file_raw_save(img, img.layers[0], filename, filename)
RuntimeError: calling error

After messing around with the filename arguments (perhaps one expected a path, and the other just a filename), the same output occurs. I was unable to find any documentation on this issue either.

My GIMP version is 2.8 and GIMP is running the script via Python 2.7.

Any suggestions?

答案1

得分: 1

你的代码在Gimp 2.10中运行正常。当我在我的Gimp 2.8中运行它时,我得到相同的调用错误。所以我认为这是后来修复的一个错误。

Gimp 2.10已经存在超过5年了,那么为什么还在使用Gimp 2.8?

英文:

Your code is OK and works in Gimp 2.10. I get the same calling error when I run it in my Gimp 2.8. So I assume it's a bug that was fixed later.

Gimp 2.10 has been around for over 5 years, so why Gimp 2.8?

huangapple
  • 本文由 发表于 2023年6月8日 06:45:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76427532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定