Python_fu插件不会加载到gimp中

时间:2016-11-04 09:38:39

标签: python gimp gimpfu

我正在尝试使用python_fu编写一个gimp插件。我希望它采用大量相同尺寸的图层并将它们放在垂直线上。这将用于打开每个页面占用一层的pdf文件,插件会将它们排成一行。当我运行插件时,菜单中没有任何内容。当我在其上方注明带有星号的行时,插件会在菜单中加载。

%USERPROFILE%\。辫形-2.8 \插件\ Array.py

from gimpfu import *

def plugin_main(timg, tdrawable, widthNum, heightNum):

    layers = gimp-image-get-layers(timg) #<< Gets a list of all the layers

    #Sets the WIDTH and HEIGHT to the size of the first image
    WIDTH = layers[0].width
    HEIGHT = layers[0].height

    #Loops through all layers and moves them
    for i in range(layers.length):
        location = float((i+1)*HEIGHT)
        #*****
        transformedimage = gimp-item-transform-2d(layers[i], 0.0, 0.0, 1.0, 1.0, 0.0, location) #<< When I comment this line out the plugin loads

    gimp-image-resize-to-layers() #<< Resizes the image to fit the moved layers

register(
        "python_fu_array",
        "Sets out your layers as tiles",
        "Sets out your layers as tiles",
        "author",
        "author",
        "2016",
        "<Image>/Image/Array",
        "RGB*, GRAY*",
        [],
        [],
        plugin_main)

main()

2 个答案:

答案 0 :(得分:2)

查看一些现有的基于Python的插件,例如https://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/py-slice.py

注意如何在那里调用某些过程,例如在第168行: https://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/py-slice.py#n168

temp_image = pdb.gimp_image_new (...)

您的代码有两个不同之处:

  1. pdb前缀
  2. 下划线而不是连字符/缩写
  3. 更改您的插件,就这样做了,您将进一步采取措施。

答案 1 :(得分:0)

除了Michael的评论,Python-fu接口defines python-style objects and classes for many Gimp concepts之外,你经常可以避免使用pdb。*函数。例如,迭代图像层:

您的代码:     layers = gimp-image-get-layers(timg)#&lt;&lt;获取所有图层的列表

#Sets the WIDTH and HEIGHT to the size of the first image
WIDTH = layers[0].width
HEIGHT = layers[0].height

#Loops through all layers and moves them
for i in range(layers.length):

更好的代码:

# better use the image height/width, layer h/w can be different
width=image.width
height=image.height

for position,layer in enumerate(image.layers):
    # etc....

我们都做错了。通过在命令提示符下调用脚本上的Python,你可以在不启动Gimp的情况下清除你最大的语法错误。如果它抱怨gimpfu,你将有机会在Gimp下运行。

  • 对于初学者Python的好建议:www.python-forum.io
  • 对于初学者Gim​​p Python的建议:www.gimp-forum.net