Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use GIMP inside a Python script?

Tags:

python

gimp

GIMP enables you to make plugin in in Python, what I would like to do is to call GIMP function like I would do inside one of this plugin but this return the following error since GIMP doesn't find any running GIMP Core to use.

LibGimpBase-ERROR **: gimp_wire_write_msg: the wire protocol has not been initialized aborting...

I would like to know if it's possible ? And if yes, how ?

Thanks

like image 438
AsTeR Avatar asked Nov 19 '11 18:11

AsTeR


People also ask

Does GIMP use Python?

GIMP-Python is different from the Script-Fu extensions. In Script-Fu, a plug-in is used to execute scripts. In GIMP-Python, the Python script takes center stage and does the work. You can instantiate the GIMP-Python scripts from inside GIMP itself, or you can use GIMP's batch mode to start it from the command line.

Can you automate in GIMP?

Running the Automation Tools on a WorkflowThe tools will open up, work on, save, and close the images one by one. In an earlier tutorial “Automated Jpg to Xcf” we outlined how to import a directory containing jpeg images into a directory with gimp xcf images.

What is Python-Fu in GIMP?

The Python-Fu console is a dialog window running a “Python shell” (a Python interpreter in interactive mode). This console is set up to make use of the internal GIMP library routines of libgimp. You can use the Python-Fu console to interactively test Python commands.


1 Answers

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.

like image 158
jsbueno Avatar answered Sep 25 '22 08:09

jsbueno