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.
- 1Linux Top 3: Fedora 24, Peppermint 7 and Solus 1.2
- 2Linux Top 3: Alpine Linux 3.4, deepin 15.2 and Linux Lite 3.0
- 3Linux 4.7 Set to Boost Live Patching, Security and Power Management
- 4Linux 4.6 Charred Weasel adds USB 3.1 Support
- 5Linux Top 3: OpenIndiana 2016.04, Ubuntu 16.04 and Debian's New Leader