Can you drive built-in gimp tools (ie- gradients, paintbrushes, filters) with python scripting?

Title is tl;dr
I’ve been using gimp to make a bunch of abstract images as a part of an art project- since I’ve found myself repeating a lot of the same operations for each composition, I’ve been wondering if there’s a way to drive any of this procedurally. I’ve poked around the Gimp Python Interface, but this documentation seems pretty old, and only seems to cover pretty direct manipulation of the image.
I don’t see any support for a case where I wanted to, say, place a radial gradient centered at a random position and then use a ‘whirl and pinch’ filter on that layer- but intuitively this feels like something that should be possible. Is this kind of scripting supported, or am I barking up the wrong tree?
Thanks!

This is something that would be easier to do with G’MIC scripting. And you’d have the benefit of accessing your work outside of GIMP too.

1 Like

This is supported. The two main calls you need:

  • pdb.gimp_drawable_edit_gradient_fill(drawable, gradient_type, offset, supersample, supersample_max_depth, supersample_threshold, dither, x1, y1, x2, y2)
  • pdb.plug_in_whirl_pinch(image, drawable, whirl, pinch, radius)
1 Like

@Paige_Gulley Welcome to the forum!

1 Like

Two helpful answers! Thanks!
Is there more up-to-date documentation available than what I linked to above? I’m in the code now, and finding that lots of little things aren’t exactly as documented- surely the interface has changed somewhat since 1999.

The doc you point to is mostly the doc of a relatively thin layer of Python objectification over the general interface. Most of the job is done by the PDB calls that are documented in the Python console (hit the Browse button).

Otherwise, not much change… The registration has changed a bit but the old one is still supported. Many changes in the PDB calls over the years but these are always up to date in the PDB browser in the Python console.

For whats its worth, one of my collection of scripts: Ofnuts’ Gimp Tools downloads

1 Like

Oh I see! I hadn’t quite grokked the pdb model, but I get it now- that’s a very cool approach to extensibility! I think I have everything I need, especially with all of your scripts in hand!

Wondering now what kinds of patterns people find useful- I guess procedural generation is kind of a niche space in gimp, but I’m imagining it happening in separate scripts rather than inside of plug-ins.

a_theory_poem_into_wizard-0
I have this more or less working, at least as a prototype! I’m generating a sequence of operations, rendering that image, then procedurally tweaking some parameter to get an animation and rendering out a bunch of frames.
Right now I’m struggling to push it over the wire- I’m trying to assemble the frames into a gif in gimp as well- I can successfully load the frames as layers into a new image, but saving out to a gif fails with an obscure error: RuntimeError: execution error

This is the line that throws:

pdb.file_gif_save(self.anim_img, self.anim_img.layers[-1], gifname, gifname, 0, 1, 100, 0)

Any insight, either into how to debug this kind of error, or what may be going on with gif_save specifially?

It’s not a show stopper- I can always step through the save prompt manually- it just would be nifty to automate end-to-end

EDIT:
cracked it open!
The issue was that the image needs to be in a indexed PALLATE color mode to save as a gif- just an undocumented detail. We’re rolling!

1 Like