1

我正在尝试使用 python_fu 编写一个 gimp 插件。我希望它采用许多相同大小的图层并将它们放在一条垂直线上。这将用于打开每个页面占据一层的 pdf 文件,插件会将它们放在一行中。但是,当我运行插件时,菜单中没有任何内容。当我注释掉上面带有星号的行时,插件会加载到菜单中。

%UserProfile%\.gimp-2.8\plug-ins\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()
4

2 回答 2

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. 下划线而不是连字符/减号

更改您的插件以执行此操作,您将获得更进一步的步骤。

于 2016-11-04T12:23:53.310 回答
0

除了 Michael 的评论之外,Python-fu 接口为许多 Gimp 概念定义了 Python 样式的对象和类,因此您可以经常避免使用 pdb.* 函数。例如迭代图像层:

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

#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
  • 对于好的初学者 Gimp Python 建议:www.gimp-forum.net
于 2016-11-04T13:22:47.507 回答