How to use GIMP inside a Python script?

GIMP's Python extensions need to be run from inside a GIMP instance. If you want to use GIMPś API from Python you have to run a GIMP without a graphical UI (passing the -i parameter from the command line) and running a custom call to the api - with the -b command line parameter - so, you can run your python_fu_do_it program, from the command line calling:

gimp -i -b \(python-fu-do-it \)

Note that this is the only way to get gimp-python extensions running: you have to run it from inside a GIMP process.

In real life, a useful thing to do might be to make your gimp-plugin expose some functions that perform actions on images that you want, and export those through an xmlrpc or jsonrpc server - which is easily done in Python. You then start this "image server" using the method above, and create stand-alone python script which call your gimp-using functions through xmlrpc.

Tags:

Python

Gimp