11

我遵循了本教程,这就是我到目前为止所提出的:

#!/usr/bin/python
# -*- coding: utf-8 -*-
#http://www.ibm.com/developerworks/library/os-autogimp/

from gimpfu import*

def plugin_main(timg, tdrawable, maxh=540, maxw=800):

    currentWidth = tdrawable.width
    currentHeight = tdrawable.height

    newWidth = currentWidth
    newHeight = currentHeight

    if (maxw < newWidth):
        newWidth = maxw
        newHeight = (float(currentHeight) / (float(currentWidth) / newWidth))

    if (maxh < newHeight):
        newHeight = maxh
        newWidth = (float(currentWidth) / (float(currentHeight) / newHeight))

    pdb.gimp_image_scale(timg, newWidth, newHeight)

register(
        "python_fu_resize",
        "Saves the image at a maximum width and height",
        "Saves the image at a maximum width and height",
        "N N",
        "N N",
        "2013",
        "<Image>/Image/Resize to max...",
        "*",
        [],
        [],
        plugin_main)

main()

但是插件不会出现在 gimp 菜单中(我使用的是 gimp 2.8)。授予文件 chmod a+x 权限。文件位置可能有问题:/.gimp-2.8/plug-ins/src/resize.py?src 是因为 Eclipse。

4

1 回答 1

13

如果您的脚本有任何语法错误,它根本不会显示在菜单中 - 上面的代码在第一行代码确实有语法错误 from gimpfu import* (在 之前缺少一个空格*

检查语法错误的一种简单方法是尝试单独运行脚本(当它在 GIMP 之外找不到“gimpfu”模块时它将失败,但到那时,语法已被解析 - 另一种方法是使用像 pyflakes 这样的 lint 实用程序来检查语法。

从 GIMP 运行脚本时,您的脚本可能包含的其他运行时错误应出现在弹出窗口中 - 在该阶段,您只能更新脚本并从菜单重试。但是,如果您从脚本更改输入或输出参数,则必须重新启动 GIMP。

是的,“文件位置” 个问题 - 您必须将代码放在 GIMP 首选项中为插件指定的目录中 - 默认情况下,这些是~/.gimp-2.8/plug-ins//usr/lib[64]/gimp/2.0/plug-ins- 没有“src” - 如果您的 IDE 不允许您指定位置要放置您的文件,您必须自己将它们复制到那里,或者src在 GIMP 首选项中添加目录。

于 2013-06-27T14:15:30.110 回答