【问题标题】:calling a gimp-fu function from an external module从外部模块调用 gimp-fu 函数
【发布时间】:2016-05-06 23:50:14
【问题描述】:

我正在尝试为 GIMP 编写一种包装器库,以使我的生成艺术项目更容易,但我在与包装器模块中的 gimpfu 交互时遇到了问题。以下插件代码运行良好,并显示带有横线的图像:

from gimpfu import *
from basicObjects import *

def newFilt() :
    img = gimp.Image(500, 500, RGB)
    background = gimp.Layer(img, "Background", 500, 500,RGB_IMAGE, 100, NORMAL_MODE)
    img.add_layer(background, 1)
    background.fill(BACKGROUND_FILL)
    pdb.gimp_context_set_brush('1. Pixel')
    pdb.gimp_context_set_brush_size(2)
    for i in range(100):
        Line= line([(0,5*i),(500,5*i)])
        pdb.gimp_pencil(background,Line.pointcount,Line.printpoints())
    gimp.Display(img)
    gimp.displays_flush()

register(
    "python_fu_render",
    "new Image",
    "Filters",
    "Brendan",
    "Brendan",
    "2016",
    "Render",
    "",
    [],
    [],
    newFilt, menu="<Image>/File/Create")

main()

'line' 类在 basicObjects 中定义,并且按预期运行,但是如果我尝试将 'pdb.gimp_pencil(background,Line.pointcount,Line.printpoints())' 替换为 'Line.draw(background )',并在 line 类中添加一个 draw() 函数,如下所示:

from gimfu import *
class line:
    """creates a line object and defines functions specific to lines """
    def __init__(self, points):
        self.points = points
        self.pointcount = len(points)*2
    def printpoints(self):
        """converts point array in form [(x1,y1),(x2,y1)] to [x1,y1,x2,y2] as nessecary for gimp pdb calls"""
        output=[]
        for point in self.points:
            output.append(point[0])
            output.append(point[1])
        return output
    def draw(self,layer):
        pdb.gimp_pencil(layer,self.pointcount,self.printpoints())

图像未呈现,gimp 错误控制台中未显示任何消息。如何从外部文件进行 pdb 调用?使包装器成为一个单独的插件会有所帮助吗?

【问题讨论】:

    标签: python wrapper gimp gimpfu


    【解决方案1】:

    首先: gimp 和 gimp-fu 模块仅在 Python 脚本作为插件从 GIMP 中运行时才起作用。我不知道您所说的“外部文件”是什么 - 但入口点始终是插件脚本。它可以像任何普通程序一样导入其他 Python 模块。

    第二:GIMP 插件运行是 Python 2.x(现在是 2.7) - 因此任何声明的类都应该继承自 object - 声明一个类而不像你那样从对象继承只会给你带来意想不到的问题- 虽然这可能不是你现在的问题。

    类声明看起来不错,但是您调用它的示例却没有 - Line.draw(background) 似乎表明您正在尝试在类本身上调用该方法,而不是在您的 line 类的实例上。

    【讨论】:

      【解决方案2】:

      是的,正如已经指出的 gimpfu 和 gimp 模块只能在 gimp 应用程序中工作,或者通过大量黑客来创建重复的环境,从没有 gimp 的脚本中运行 gimp 扩展和插件会很酷应用程序开销,但这基本上是能够同时吃蛋糕的情况。如果您不需要 gimp 提供的所有过滤器和效果,您可以考虑使用 PIL / Pillow 模块。它们没有达到 gimp 的能力,但具有图形图像处理的所有基本功能。那些在 python2 或 3 中运行良好,并且比 gimp 快得多。

      【讨论】:

        【解决方案3】:

        是的,可以执行存储在磁盘上任何位置的 python-fu 脚本,可能使用 PYTHONPATH 和 DYLD_LIBRARY_PATH。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-07-04
          • 1970-01-01
          • 2022-12-03
          • 2020-01-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多