从外部模块调用gimp-fu函数

问题描述 投票:2回答:2

我正在尝试为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) ',然后向该线类添加一个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
2个回答
1
投票

第一:gimp和gimp-fu模块仅在GIMP中将Python脚本作为插件运行时才起作用。我不知道您所说的“外部文件”-但是入口点必须始终是插件脚本。他们可以将其他Python模块作为任何常规程序导入。

[第二:GIMP插件运行于Python 2.x(目前为2.7)-因此,任何声明的类都应继承自object-声明类而不像从对象继承那样只会给您带来意想不到的问题-尽管这可能现在不是您的问题。

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


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.