Writing a script to automate incremental image renders from a specific G'MIC effect

This is about a specific effect, but I’m curious about doing this for G’MIC procedures in general, I’m assuming that writing a script is the way to go after a couple of hours of unsuccessfully trying to get it to work through the script-fu console as an inexperienced scripter.

With one click, I’d like to take an image-> apply an effect → export as a new image → incrementally change one setting of that effect → export that as a new image → incrementally change that one setting further → export that as a new image… etc, etc. The intention is to automate frame renders for fluid animations.

The issue I seem to be running into is the Popcorn Fractal Effect that I’d like to do this with, available in the G’MIC-qt plug-in for GIMP. This effect is apparently not available through the G’MIC CLI, or else this’d be fairly easy to set-up, as I could just make a Txt file with the different variations, but we seem to be stuck in the QT plug-in for this.

The best hint in the right direction I found online ended up with this string of code

(plug-in-gmic-qt 1 img Background.png 0 0 “-v - -fx_rep_pfrac 50,1,0.05,3,1,0,50,50,0,1,0,1,2,0,1,2,0,1,2,0,1,0,0”)

I can’t seem to get script-fu to read even this example + run it, I’m not sure if it needs to be registered or if you can run singular commands like this.

Any help would be appreciated.

1 Like

It should be available. G’MIC-Qt and gmic uses the same set of filters/commands.
For older versions of gmic, you may have to force it with gmic update, but with recent versions, both share filters.

Actually, I strongly suggest using gmic rather than trying to script the plug-in, that will be more efficient.
For the popcorn fractal example, here is a simple command thats does the job. You can modify it according to your needs:

foo :
  repeat 100 { # Number of frames
    e "- Frame "$>
    frac:=$>/($>+$<) # 'frac' will go from 0 to 1.
    zoom:=lerp(0.5,1.5,$frac) # 'zoom' will go from 0.6 to 1.5
    angle:=lerp(0,180,$frac) # 'angle' will go from 0 to 180
    512,512,1,3 # Input a new color image
    fx_rep_pfrac 50,1,0.05,3,$zoom,$angle,50,50,0,1,0,1,2,0,1,2,0,1,2,0,1,0,0 # The command to execute the filter
    cut. 0,255 # Be sure output values stay in range [0,255]
    on. frame.png,$> w. rm # Save current, and display it
  }

Put this in a text file like foo.gmic, then use gmic like this:

$ gmic foo.gmic foo

This will generate the following frames (here, converted directly as an animated .gif):
anim

1 Like

That’s great, this is exactly what I’m trying to get working, I’d rather be doing this kind of stuff through the terminal anyway.

Right now, following your directions, I’m saving the commands you’ve shared as a text file named foo.gmic, then opening a terminal from the folder the txt file is in, and running the command

$ gmic foo.gmic foo

But this is the response from my terminal

Screenshot from 2024-09-17 18-57-52

Does the text file have to be saved to a specific place/ format or does there have to be an image in the folder to work off of?

I have almost no experience with generating media like this, your help is greatly appreciated.

I’m currently having issues bringing this effect up in the CLI even individually

running this command ends up with an error -

gmic Frame1.png fx_rep_pfrac 50,1,0.05,3,1,0,50,50,0,1,0,1,2,0,1,2,0,1,2,0,1,0,0

Screenshot from 2024-09-17 19-09-53

and trying to update the specific filter returns

Screenshot from 2024-09-17 19-11-24

It’s working fine through GIMP interestingly enough

Your screenshots make me think that you’re using a fairly old version of gmic on the command line (maybe older than the plug-in, so the filters could not be up to date).
Could you first please check:

~$ gmic -version

  gmic: GREYC's Magic for Image Computing: Command-line interface
        Version 3.4.3
        (https://gmic.eu)

        Copyright (c) Since 2008, David Tschumperlé / GREYC / CNRS.
        (https://www.greyc.fr)

Latest stable version is 3.4.2 (mine is 3.4.3_pre actually).

I would recommend downloading latest version 3.4.2 for your tests, and try again.
The .gmic file does not have to follow a specific format, nor be saved in a specific place, it is just a plain text file that must be readable when you invoke gmic from the CLI.

Let’s do it step by step, and I’m sure we will find a solution !

You were correct, I had downloaded a couple different versions of G’MIC when installing the plug-in for GIMP and somehow this version managed to find it’s way into the CLI

Screenshot from 2024-09-18 22-50-15

I downloaded and installed the latest version 3.4.2, ran the txt file fine with no issues, and was able to pull out a GIF like the one you shared, it seems the outdated version was the cause

test

Thanks so much for your help! I plan on using this exact method for animations and artwork with all sorts of content, and can use this one command file as a template. I appreciate your assistance and the G’MIC software.

2 Likes

Great news!
Indeed, version 2.9.4 is a bit old (Nov. 2020), and G’MIC has evolved a lot since then.

Feel free to share your work here, it’s always interesting to see new use cases for the G’MIC CLI tool!

Highly appreciated, I’m working on an art collection based off a couple of specific formulas I found while exploring this effect, this is the difference between exporting the images one at a time manually vs. printing out the whole animation from a text file.

I’ll share some of the works when it’s finished, cheers!

1 Like