我正在尝试为 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() 函数添加到 line 类,如下所示:
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 调用?使包装器成为一个单独的插件会有所帮助吗?