Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python-fu/gimpfu parameters - What does "image" mean?

I've been trying to switch from script-fu to python-fu, and I can't figure out what I'm supposed to pass for the "image" parameter. In script-fu it was just an integer, but when I put the same integer into python-fu, it just says it's the wrong type. Same with strings and floats... what am I supposed to put in here? The documentation just says the parameter it takes is "IMAGE" but what does that mean? Where do I find it? How do I get it?

pdb.gimp_image_get_layers(image)

Here's a picture of the interpreter.

like image 947
Zaay'd Avatar asked Feb 02 '16 06:02

Zaay'd


1 Answers

You pass an Image object - Most of the parameters that are only integers in script-fu are not to be used - in their place, you have to pass an actual object reference. ANd how do you get those?

Simply all PDB functions and methods return these objects already - not their numeric IDs, like it happens in script-fu.

So, for Image, you either get the Image as parameter for your python-fu function, or on a call to pdb.gimp_image_new.

If, as it is often the case, you are making tests on the interactive console, you have to get references to the active images. In that case, call gimp.image_list() to get a Python list with the currently open images - the image at index 0 on this list is the rightmost (newest) open image on the screen -so just do image = gimp.image_list()[0] to get a reference to it.

While you are at it, explore the image object with dir(image) you willfind it is populated with attributes and methods that are handy shortcuts to otherwise hard-to-type pdb calls. For example, image.layers gives you a Python list with reference to all layers on the image (as actual Layer objects, not their IDs), image.width gives you the width, and calling img.new_layer() creates a new layer and adds it to the image - this call has optional parameters to specify its name, width, height and so on.

As a last resort, there are reserved methods on the gimp module that can convert a numeric ID to the actual objects: '_id2display', '_id2drawable', '_id2image', '_id2vectors' - you should not need to use those. If you ever find your self needing to use those in the body of a script, due to some pdb function returning IDs instead of objects, please fill a bug report on GIMP's bugzilla.

like image 113
jsbueno Avatar answered Sep 19 '22 15:09

jsbueno