Gimp –no-interface –batch ‘(python-fu-console-echo RUN-NONINTERACTIVE “another string” 777 3.1416 (list 1 0 0))’ ‘(gimp-quit 1)’ GIMP Python All this means that you could easily invoke a GIMP Python plug-in such as the one above directly from your shell using the (plug-in-script- fu-eval …) evaluator:
The first small issue I’ve encountered in my attempt to write a batch script, is that GIMP only accepts Python code as command line argument, not the path to a script on disk. This allows for very powerful scripting capabilities. This is the nice thing about GIMP scripting: it lets you manipulate layers just like in the UI. What the code does is to take the first image from the list of open images and sets the opacity of the first layer to 50%. But GIMP is actually nice, you can do many complex UI operations from code and you also have an interactive Python shell to test your code live on an image.įor example, open an image in GIMP, then open the Python console from Filters -> Python-Fu -> Console and execute the following code: img = gimp.image_list()Īnd you’ll see that the image is now halfway transparent. Of course, I could’ve tried other solutions like PIL (Python Imaging Library) which I have used in the past. Just to mention, GIMP supports also a Lisp syntax to write scripts, but it caused my eyes to bleed profusely, so I didn’t even take into it consideration and focused directly on Python. So I thought, why not using a GIMP batch command, since anyway GIMP is installed on most Linux systems by default? One of the produced images had to be semi-transparent. To those wondering why GIMP, it’s because I created a new icon for Profiler and wanted to automatize some operations on it in order to have it in all sizes and flavors I need. You can jump to the end of the tutorial to find a nice skeleton batch script if you’re not interested in reading the theory.
I spent a total of one hour researching this topic, so I’m not an expert and I could have made mistakes, but perhaps I can save some effort to others which want to achieve the same results. I won’t go into the details of the Python GIMP SDK, most of it can be figured out from the GIMP documentation. Not a very common topic for me, but I thought it could be neat to mention some tips & tricks.