Writing Plugins for GIMP in Python - page 2
Creating a ScriptAll GIMP plug-ins, regardless of language, need to call register to tell GIMP they exist. Here's a skeleton of a GIMP-Python plug-in showing how to register. Copy and paste this into pytest so you can see how it works:
def python_pytest(img, layer) : # Actual plug-in code will go here return register( "python_fu_pytest", "Does something", "Does something terribly useful", "Your name", "Your name", "2009", "Py Test...", "*", [ ], , python_pytest, menu="/Filters/Distorts") main()
What does all that mean? The first part, def python_pytest, is the routine that will do the real work ... but for now, it's just a placeholder. It takes two arguments, the image and layer to work on. Any plug-in that modifies an existing image must use at least these two arguments. Plug-ins that create new images don't need them.
register is next. It takes quite a list of arguments:
- A python_fu name by which your function will be available to other GIMP scripts;
- Short and long descriptions of what the plug-in does;
- The name of the author and the copyright holder (usually the same person) and the copyright date;
- The name the plug-in should use in the menus;
- The types of images your plug-in can handle (RGB, greyscale, indexed or all). If it can work on any type of image, use "*"; if it creates a new image rather than operating on an existing one, use "";
- Any parameters the plug-in might show to the user -- I'll show how to use these in a future article;
- Any return values. Most python scripts leave this blank, or ;
- The name of the function that does the work, python_pytest;
- Where in the menus you want the function to show up.
Whew! Quite a lot of arguments, but usually you can copy most of them from some other plug-in and just change the values; you don't have to remember all of that.
Sponsored by BlackBerry
BlackBerry® Enterprise Server Express enables businesses of any size to quickly and easily get started with the BlackBerry solution. It provides advanced BlackBerry smartphone features with no additional software or user license fees, and works with any Internet-enabled BlackBerry data plan or a BlackBerry enterprise data plan. Download now!