Reputation: 799
I am trying to write a gimp plugin using python_fu. I want it to take lots of identically sized layers and put them in a vertical line. This would be used for opening pdf files where each of the pages occupies one layer, and the plugin would put them in a line. When I run the plugin though, nothing appears in the menu. When I comment out the line with an asterisk above it the plugin loads in the menu.
%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()
Upvotes: 1
Views: 663
Reputation: 8914
In addition to Michael's remark, the Python-fu interface defines python-style objects and classes for many Gimp concepts so you can very often avoid the pdb.* functions. For instance to iterate the image layers:
Your code: 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):
Better code:
# 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....
We all do errors. You can weed out your biggest syntax blunders without even starting Gimp, by calling Python on your script in a command prompt. If it goes as far as complaining about gimpfu, you will stand a good chance that it will run under Gimp.
Upvotes: 0
Reputation: 538
Have a look at some existing Python-based plug-ins, for example https://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/py-slice.py
Notice how some procedures are called there, for example in line 168: https://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/py-slice.py#n168
temp_image = pdb.gimp_image_new (...)
There are two differences to your code:
Change your plug-in to do it like this, and you'll get a few steps further.
Upvotes: 2