【问题标题】:Error: ( : 1) Invalid number of arguments for python-fu command line execution错误:(:1)python-fu命令行执行的参数数量无效
【发布时间】:2017-05-02 23:20:38
【问题描述】:

我已将以下 python 脚本添加到 /usr/lib/gimp/2.0/plug-ins 文件夹

#!/usr/bin/python

from gimpfu import *

def scale(imageName):
    pass

register(
    "my",
    "",
    "",
    "",
    "",
    "2017",
    "<Image>/Image/Hi..",
    "RGB*, GRAY*",
    [(PF_STRING, 'file_name', 'file_name', 'logo.png')],
    [],
    scale)

main()

通过运行它

gimp --no-interface -b '(python-fu-my RUN-NONINTERACTIVE "logo.png")' -b '(gimp-quit 0)'

返回

批处理命令遇到执行错误:错误:(:1)无效 python-fu-my 的参数数量(预期为 4,但 收到 2)

在 Gimp 的程序浏览器中确实有 4 个参数,但如果程序是通过命令行运行的,它不应该期望它们,不是吗?

我关注了docs。 怎么了?

【问题讨论】:

  • 尝试暂时将imageName 更改为*imageName,这将收集提供给函数的所有参数,并且在太多/太少时不会报错。然后您可以将它们打印出来并查看实际传递的内容。

标签: python gimp python-fu gimpfu


【解决方案1】:

您不应该将该函数注册为插件,而应该直接调用它 (scale("logo.png"))。但是您的代码必须显式加载图像文件才能获得 gimp.Image 对象。

【讨论】:

  • 嗨,如果我直接运行它,我会得到 gimp_wire_write_msg: the wire protocol has not been initialized 错误
  • "直接运行" stll 表示使用 Gimp。像gimp --no-interface -b '(scale logo.png")' -b '(gimp-quit 0)' 这样的东西。您可能需要调整 python 路径并显式导入脚本:gimp-idf --batch-interpreter python-fu-eval -b 'import sys; sys.path=["."]+sys.path;import yourscript;yourscript.run("logo.png")' -b 'pdb.gimp_quit(1)
猜你喜欢
  • 2012-11-22
  • 2011-03-30
  • 2017-06-17
  • 1970-01-01
  • 2023-01-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-15
相关资源
最近更新 更多