Writing Plugins for GIMP in Python - page 3
Creating a ScriptOnce you have your plug-in's skeleton in place, it's time to see if it registers right. Quit GIMP if it's already running, re-start it, and see if your plug-in shows up in the menu -- in this case, somewhere under Filters->Distorts (Figure 1).
Writing the plug-in
Once you have your plug-in showing up in the menus, the rest is easy! Just call functions to do the same things you would have done yourself in GIMP. For this short article, let's do something very simple: flip the current image upside down.
How do you figure out how to do that? With the GIMP Procedure browser, available from GIMP's Help menu. In GIMP 2.4 and earlier it was in the Xtns menu inside the Toolbox window.
Open the Procedure Browser and search for flip (Figure 2).
There are a lot of different flip routines there; for now, let's pick one that looks simple, gimp-image-flip.
The Procedure Browser shows that it takes two parameters: the image to flip, and a flip-type that can be ORIENTATION-HORIZONTAL (0) or ORIENTATION-VERTICAL (1).
Here's how that translates into Python:
def python_pytest(img, layer) : pdb.gimp_image_flip(img, ORIENTATION_VERTICAL)
Make that change to your pytest file, and try it! No need to restart again -- once you've registered, GIMP knows where the file is and will pick up whatever changes you make. You only need to restart when you change something in the register() function.
So run Filters->Distorts->Py Test, and voil´┐Ż! The image is flipped upside down (Figure 3). It's that simple.
In the next article, I'll show you how to use plug-in arguments to make a plug-in that does something much more useful.
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: Linux Mint Olivia, Fedora 19's Cat and Ubuntu's Mission Accomplished Moment
- 2Linux Top 3: Linux 3.10 Goes Long, Linux 3.11 Advances as LXDE Merges
- 3Why Linux is Super (Computing)
- 4Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 5Linux 3.10 Improves Multi-tasking and SSD Caching