From GIMP Developer Wiki
Revision as of 20:51, 23 May 2011 by Bootchk (Talk | contribs)

Jump to: navigation, search

GIMP supports plug-ins.

Some plug-ins are distributed with GIMP and some are distributed by third parties.

Getting Started

A good way to get started is to read plug-ins distributed with GIMP.

You can test snippets of Scheme and Python plug-ins on the consoles available in GIMP at the menu items: Filters>Script-Fu>Console and Filters>Python-Fu>Console. A console is a terminal window that lets you enter and execute statements in the programming language.

The documentation for the PDB is available in GIMP at the menu item: Help>Procedure Browser.

Plug-ins and the GIMP Procedural DataBase (PDB)

Plug-ins must register themselves in the PDB. Other GIMP functions, called internal procedures, are also in the PDB. An internal procedure often provides a function also found in the GIMP menus.

Registration means declaring the name and parameters of a plug-in, as well as declaring where a plug-in will appear in the GIMP menus, if at all.

A plug-in commonly calls other plug-ins in the PDB.

(Note that the procedures in the PDB are often similar to procedures in the GIMP library, but have different signatures. Do not confuse the two.)

Programming Languages for GIMP Plug-ins

GIMP plug-ins are written in the C, Scheme, Python, or Perl programming languages.

C language GIMP plug-ins are compiled and linked with Gimp libraries. They can access functions in those libraries or functions in the PDB. They are distributed as executable files with suffix ".exe".

Scheme language GIMP plug-ins are interpreted. They can access procedures in the GIMP Procedural Database (PDB) as well as the functions built into the Scheme language. They are distributed as text files called scripts with suffix ".scm".

Python language GIMP plug-ins are interpreted. They can access procedures in the GIMP Procedural Database (PDB) as well as functions provided by the PyGimp set of Python modules (chiefly, the module named "gimpfu") and functions provided by the Python modules in a standard Python distribution. They are distributed as text files with suffix ".py".

Choosing a Language for a GIMP Plug-in

Plug-ins are usually usually written in the C language if they implement fundamental algorithms at the pixel level. Such plug-ins might need the speed of a compiled language and full access to the GIMP libraries. However, such plug-ins need to be separately compiled for each platform.

Plug-ins written in Scheme or Python usually implement less compute intensive algorithms. Often they implement recipes: step-by-step sequences of actions a user could do manually using the GIMP. They are limited to GIMP functions found in the PDB (they can't directly access the Gimp C libraries.) They are very portable (assuming the separate Python interpreter is installed.)

Plug-ins in C can provide any user interface using, for example, the GTK toolkit. Plug-ins written in Scheme or Python can easily provide a dialog for plug-in settings using a standard set of widgets provided (by the Scheme interpreter and the PyGimp modules) for the parameters of the plug-in. Plug-ins written in Python can provide fuller user interfaces by using, for example the PyGTK toolkit, which is in a standard Python distribution.

C is an older language, the traditional programming language for systems level programming with full access to the underlying hardware and operating system. It is powerful but unforgiving.

Scheme is a Lisp-like language with a very simple syntax. Some people find it hard to learn and difficult to read. The set of functions distributed with the Scheme interpreter built into Gimp is what the language provides, so you might need to include third party Scheme functions inside your plug-in.

Python is a more recent language. It supports programming concepts such as object orientation and exceptions. Since it is interpreted, it supports agile programming or rapid prototyping. Most Python programs are written idiomatically, using common phrases. Some people find Python abstractions and idioms difficult to learn. The set of modules in a standard Python distribution provides a rich set of components.

Debugging GIMP Plug-ins

Generally, debugging Scheme and Python plug-ins is easier. Python provides a trace when a plug-in throws an exception. Python also has a convenient logging module.

You can use the technique of embedding print statements or logging statements in your plug-in. Start GIMP from a console (a terminal window) to see the output of your debugging statements to stdout or stderr (the standard output streams for a program.)

You can also debug plug-ins using a run-time debugger, such as the GNU debugger, gdb, or a memory debugger, such as valgrind or purify. Since a plug-in is started from within GIMP and runs as a separate process from GIMP, you generally "attach" a running plug-in to a debugger. Or, for example, instead of you starting the debugger, GIMP starts the debugger when you start a plug-in from within GIMP. See [1] for more information. Generally a debugger is more useful for C-language programs. Using a debugger you might find yourself reading GIMP code instead of your plug-in code.

Community of GIMP Plug-in Authors

Many authors of GIMP Scheme and Python plug-ins lurk at:

Gimp Plugin Registry


Generally, there are fewer authors of C-language GIMP plug-ins. The community of GIMP developers are mostly C programmers but they don't often write plug-ins. Questions to GIMP developers concerning C-language plug-ins are discouraged for all but difficult questions. Bugs in third-party plug-ins (those not distributed with GIMP) should NOT be reported as GIMP bugs, only reported to the author or maintainers of the third-party plug-ins.

References for Programming GIMP Plug-ins

A tutorial on programming GIMP plug-ins in the C language.

A tutorial on programming GIMP plug-ins in the Scheme language.

GIMP Python Documentation.

A tutorial on programming GIMP plug-ins in Python.

The GIMP 2.0 API Reference This documents the GIMP C library, not the GIMP Procedural Database! The PDB is best examined from within GIMP using Help>Procedure Browser