Automating Gradient Flare Animations in GIMP 3 Using Script-Fu

Introduction

Gradient flares are a great way to create glowing stars, expanding light effects, bright suns, and cinematic energy bursts in digital artwork. GIMP's Gradient Flare filter provides several built-in flare presets that can be used to produce these effects.

gradient-flare-scripting-05.jpg

But what if you want to create an animation where a gradient flare gradually expands over time?

Instead of manually creating individual frames, adjusting the flare radius, and repeating the process, you can automate the entire workflow using GIMP Script-Fu.

In this tutorial, we'll explore a Script-Fu plugin that automatically generates a gradient flare animation by creating multiple layers and progressively increasing the flare radius for every frame.

The script allows you to configure:

  • Image width and height.
  • Number of animation frames.
  • Gradient flare preset.
  • Flare expansion radius.

By the end of this tutorial, you'll understand how to use GIMP 3's Script-Fu API to automate repetitive image-processing tasks and generate animation-ready layers.

1. Understanding the Animation Workflow

Before looking at the code, let's understand how the animation is generated.

The basic idea is simple:

  1. Create a new RGB image.
  2. Add a black background layer.
  3. Create multiple transparent or background-filled layers.
  4. Apply the Gradient Flare filter to each layer.
  5. Increase the flare radius with every iteration.
  6. Display the resulting image containing all animation frames.

For example, if we generate 30 frames, the flare radius increases progressively:

Frame Flare radius
1 101
2 102
3 103
4 104
5 105
… …
30 130

Each layer represents a different stage of the expanding flare.

When these layers are played sequentially using GIMP's animation playback functionality, they produce an expanding light effect.

2. Registering the Script-Fu Plugin

Let's start with the plugin registration code.

(script-fu-register
 "script-fu-gradient-flare-animation"
 "Gradient-Flare-Animation"
 "Create a gradient flare animation by increasing radius for every frame"
 "Rajasegar Chandran"
 "Rajasegar Chandran"
 "December 2026"
 ""
 ...
)

The `script-fu-register` function registers the procedure with GIMP and defines the information and parameters required to display its user interface.

Let's understand each argument.

Parameter Description
Procedure name Internal name used to invoke the Script-Fu procedure
Menu label Name displayed in GIMP
Description Short explanation of the plugin
Author Plugin author
Copyright Copyright information
Date Plugin creation or release date
Image types Supported image types; an empty string means no image-type restriction here

The procedure name is:

"script-fu-gradient-flare-animation"

This is the function GIMP will invoke when the user runs the plugin.

The menu label is:

"Gradient-Flare-Animation"

This is the name displayed in the GIMP menu.

3. Creating the Plugin User Interface

gradient-flare-scripting-01.jpg

The next section defines the parameters that users can configure when running the plugin.

3.1 Image Width

SF-ADJUSTMENT "Width (pixels)"
'(1000 2 9999 1 10 0 1)

This creates a numeric adjustment control for specifying the image width.

The adjustment arguments are:

(default minimum maximum step
 page-increment digits slider?)

For this example:

  • Default value: 1000 pixels.
  • Minimum value: 2 pixels.
  • Maximum value: 9999 pixels.
  • Step increment: 1 pixel.
  • Page increment: 10 pixels.
  • Decimal digits: 0.

3.2 Image Height

SF-ADJUSTMENT "Height (pixels)"
'(1000 2 9999 1 10 0 1)

This parameter works exactly like the width parameter, but controls the image height.

The default canvas size is therefore 1000 × 1000 pixels.

3.3 Number of Animation Frames

SF-ADJUSTMENT "Frames"
'(30 2 999 1 10 0 1)

This parameter determines how many layers the plugin will generate.

The default is 30 frames.

Increasing this value creates more layers and gives you a longer animation sequence.

For example:

  • 10 frames: Short animation.
  • 30 frames: Medium animation.
  • 60 frames: Longer animation.
  • 100 frames: More detailed animation.

Remember that increasing the frame count also increases processing time and memory consumption.

3.4 Selecting the Gradient Flare Preset

gradient-flare-scripting-06.jpg

SF-OPTION "Flare"
'("Bright_Star"
  "Classic"
  "Default"
  "Distant_Sun"
  "GFlare_101"
  "GFlare_102"
  "Hidden_Planet")

This creates a dropdown selection containing seven Gradient Flare presets.

Each preset produces a different visual appearance.

For example:

  • `Bright_Star`: A bright star-like flare.
  • `Classic`: A traditional lens-flare appearance.
  • `Default`: The default gradient flare.
  • `Distant_Sun`: A sun-like glowing effect.
  • `GFlare_101` and `GFlare_102`: Additional flare variations.
  • `Hidden_Planet`: A planet-inspired flare effect.

The selected option is passed to the main procedure as an integer index, starting at zero.

4. Registering the Plugin in the GIMP Menu

(script-fu-menu-register
 "script-fu-gradient-flare-animation"
 "<Image>/Filters/Testing")

This statement adds the plugin to GIMP's menu system.

After installing and refreshing the plugin, you can find it under:

Filters → Testing → Gradient-Flare-Animation

The `<Image>` prefix indicates that the procedure is registered in the image-related menu hierarchy.

5. Defining the Available Flare Presets

(define flares
  '("Bright_Star"
    "Classic"
    "Default"
    "Distant_Sun"
    "GFlare_101"
    "GFlare_102"
    "Hidden_Planet"))

Here, we define a Scheme list containing all available flare preset names.

Why do we need this list when we've already defined the dropdown options?

The reason is that the dropdown returns an integer representing the selected option, rather than the actual preset name.

We can retrieve the corresponding preset using:

(list-ref flares flare)

For example:

Dropdown selection Index Retrieved preset
Bright_Star 0 Bright_Star
Classic 1 Classic
Default 2 Default
Distant_Sun 3 Distant_Sun
GFlare_101 4 GFlare_101
GFlare_102 5 GFlare_102
Hidden_Planet 6 Hidden_Planet

This makes it easy to dynamically select the correct flare preset.

6. Defining the Main Animation Function

Now let's look at the main procedure.

(define (script-fu-gradient-flare-animation
         width height frames flare)

This function accepts four arguments:

Argument Purpose
width Image width
height Image height
frames Number of animation frames
flare Selected flare preset index

These values are supplied automatically by GIMP when the user runs the plugin.

Next:

(script-fu-use-v3)

This activates the Script-Fu version 3 compatibility environment.

The plugin uses GIMP 3's procedure API and modern drawable and layer operations.

7. Creating a New RGB Image

(let* ((img
        (gimp-image-new width height RGB))

       (background
        (gimp-layer-new
         img
         "Background"
         width
         height
         RGB-IMAGE
         100
         LAYER-MODE-NORMAL)))

The `let*` expression creates local variables that can be used throughout the function.

It initializes two important objects.

7.1 Creating the Image

(gimp-image-new width height RGB)

This creates a new RGB image using the dimensions specified by the user.

For example, if the user enters:

width  = 1000
height = 1000

GIMP creates a 1000 × 1000 pixel RGB image.

7.2 Creating the Background Layer

(gimp-layer-new
 img
 "Background"
 width
 height
 RGB-IMAGE
 100
 LAYER-MODE-NORMAL)

This creates a new image layer.

Its arguments specify:

  • Image to which the layer belongs.
  • Layer name.
  • Layer width.
  • Layer height.
  • RGB image type.
  • Opacity of 100%.
  • Normal blending mode.

The newly created layer will serve as the black background for our animation.

8. Inserting and Filling the Background

(gimp-image-insert-layer img background 0 0)

Creating a layer doesn't automatically add it to the image.

This function inserts the background layer into the image.

The final arguments specify its parent and position in the layer stack. A parent value of `0` means the top-level layer tree, and the final `0` places it at the top.

Next, we fill the background with black.

(gimp-context-set-background '(0 0 0))
(gimp-drawable-fill background FILL-BACKGROUND)

The first statement sets the current background color to black.

RGB values:

'(0 0 0)

represent:

  • Red: 0
  • Green: 0
  • Blue: 0

The second statement fills the background layer using the currently configured background color.

This gives us a black canvas on which the flare effects will be rendered.

9. Starting an Undo Group

(gimp-image-undo-group-start img)

This statement starts an undo group for the image.

Why is this useful?

Our plugin creates multiple layers and performs several operations on each layer. Without grouping, these operations could generate a large number of individual undo steps.

An undo group helps organize the operations into a single logical action.

At the end of the script, we'll close this group using:

(gimp-image-undo-group-end img)

10. Generating Animation Frames Using a Loop

This is the most important part of the plugin.

(do ((i 1 (+ i 1)))
    ((= i (+ 1 frames)))
    ...)

The `do` expression is a Scheme looping construct.

It allows us to execute the same block of code repeatedly while incrementing a counter.

Let's break it down.

(do ((i 1 (+ i 1)))

This initializes the variable `i` with a value of 1.

After every iteration, its value increases by 1.

((= i (+ 1 frames)))

This specifies the loop termination condition.

The loop stops when `i` becomes equal to `frames + 1`.

For example, if the user specifies 30 frames:

i = 1, 2, 3, 4, ... 30

The loop executes exactly 30 times.

Each iteration creates one animation layer.

11. Creating a Layer for Every Frame

Inside the loop, we create a new layer.

(let ((layer
       (gimp-layer-new
        img
        "Layer"
        width
        height
        RGB-IMAGE
        100
        LAYER-MODE-NORMAL)))

Each iteration creates a new RGB layer with the same dimensions as the original image.

Next:

(gimp-image-insert-layer img layer 0 0)

This inserts the new layer into the image.

Because the position is zero, each new layer is inserted at the top of the layer stack.

Then:

(gimp-drawable-fill layer FILL-BACKGROUND)

This fills the layer with the current background color, which is black.

The Gradient Flare filter will then render the flare onto this layer.

One detail worth understanding: the script creates opaque black layers rather than transparent layers. This means the layers are intended as independent animation frames, not as transparent flare overlays.

12. Applying the Gradient Flare Filter

Now we reach the core image-processing operation.

(plug-in-gflare
 #:run-mode RUN-NONINTERACTIVE
 #:image img
 #:drawables (vector layer)
 #:gflare-name (list-ref flares flare)
 #:center-x (/ width 2)
 #:center-y (/ height 2)
 #:radius (+ (* 1 i) 100))

The `plug-in-gflare` procedure invokes GIMP's Gradient Flare filter programmatically.

gradient-flare-scripting-04.jpg

Instead of manually opening the filter dialog and configuring it for every layer, we supply all the required parameters directly.

Let's examine them individually.

12.1 Noninteractive Execution

#:run-mode RUN-NONINTERACTIVE

This tells GIMP to execute the filter without opening its interactive configuration dialog.

It's essential for automation because the plugin needs to generate multiple frames without requiring user intervention.

12.2 Target Image

#:image img

This specifies the image on which the filter should operate.

12.3 Target Drawable

#:drawables (vector layer)

This specifies the layer on which the Gradient Flare filter should operate.

The `vector` expression converts the layer into a vector containing the drawable.

This is the drawable argument format used by GIMP 3's modern procedure interface.

12.4 Selecting the Flare Preset

#:gflare-name (list-ref flares flare)

This retrieves the selected preset name from our `flares` list.

For example, if the user selects `Bright_Star`, the expression evaluates to:

"Bright_Star"

This allows the same animation generator to work with different visual styles without changing the code.

12.5 Positioning the Flare

#:center-x (/ width 2)
#:center-y (/ height 2)

These expressions calculate the horizontal and vertical coordinates of the canvas center.

For a 1000 × 1000 image:

center-x = 500
center-y = 500

Therefore, every flare is positioned in the center of the canvas.

You can modify these expressions to position the flare anywhere you want.

For example:

#:center-x (/ width 4)
#:center-y (/ height 4)

This positions the flare at approximately one-quarter of the canvas width and height.

12.6 Increasing the Flare Radius

This is the key expression responsible for creating the animation effect.

#:radius (+ (* 1 i) 100)

Let's simplify it.

First:

(* 1 i)

Multiplies the current frame number by 1.

Then:

(+ (* 1 i) 100)

Adds 100 to the result.

Therefore:

radius = 100 + frame_number

For 30 frames, the radius changes from 101 to 130.

This produces a progressively expanding flare.

You can experiment with different expressions to change the animation speed.

For example:

Slow expansion

#:radius (+ 100 (* 0.5 i))

Fast expansion

#:radius (+ 100 (* 5 i))

Accelerating expansion

#:radius (+ 100 (* i i))

These expressions change how quickly the flare grows between successive frames.

13. Completing the Animation Generation

After all iterations are completed, the script executes:

(gimp-image-undo-group-end img)

This closes the undo group that was opened earlier.

Finally:

(gimp-display-new img)

This opens the newly generated image in GIMP.

You should now see a new image containing the black background and all the generated flare layers.

Each layer represents one stage of the expanding flare.

gradient-flare-scripting-02.jpg

14. Visualizing the Animation Concept

The following illustration describes the intended progression of the flare radius.

Frame Visual progression
Frame 1 Small flare
Frame 2 Slightly larger flare
Frame 3 Expanding flare
Frame 4 Medium-sized flare
Frame 5 Larger flare
Frame 6 Maximum expansion

The important concept is that every frame uses the same flare preset and center position, but a different radius.

This is a simple example of parameter-driven animation: rather than manually drawing each frame, we change a mathematical parameter and let GIMP generate the corresponding visual output.

15. How to Turn the Generated Layers into an Animation

The current script generates animation frames as layers. It doesn't automatically export a GIF or configure animation playback timing.

To turn the layers into an animation:

  1. Run the plugin and generate the frames.
  2. Open GIMP's Filters → Animation → Playback.
  3. Preview the generated layer sequence.
  4. Adjust the layer order if necessary.
  5. Export the image as GIF.
  6. Select the option to save as animation.
  7. Configure the frame delay and looping options.

For a smoother animation, you can experiment with 30–60 frames and a frame delay of around 50–100 milliseconds.

gradient-flare-scripting-03.jpg

16. Ideas for Improving the Script

Once you understand the basic implementation, there are several ways to extend it.

A. Add a Flare Expansion Speed Parameter

Instead of hardcoding the expansion multiplier, expose it as a user-configurable parameter.

For example:

#:radius (+ 100 (* speed i))

This allows users to control how quickly the flare expands.

B. Add Custom Flare Position

Add two more adjustment controls:

SF-ADJUSTMENT "Center X" ...
SF-ADJUSTMENT "Center Y" ...

This would allow users to position the flare anywhere on the canvas.

C. Animate Flare Position

Instead of keeping the flare centered, gradually move it across the canvas.

For example:

#:center-x (+ 100 (* 10 i))
#:center-y (+ 100 (* 5 i))

This produces a moving flare effect.

D. Animate Flare Radius Using Different Mathematical Functions

You can use different mathematical expressions to create different expansion patterns.

Linear expansion:

(+ 100 (* 2 i))

Quadratic expansion:

(+ 100 (* i i))

Exponential-style expansion:

(+ 100 (expt 1.1 i))

Sinusoidal radius variation:

(+ 150 (* 50 (sin (* i 0.2))))

These expressions open up many possibilities for procedural animation.

Download

You can download the complete script here

Copy the file to your GIMP scripts folder and restart GIMP.

It will be available under Filters-> Testing -> Gradient-Flare-Animation

Conclusion

flare.gif

This Script-Fu plugin demonstrates how GIMP 3 can be used as a procedural animation-generation tool.

By combining image creation, layer manipulation, looping constructs, and the Gradient Flare filter, we can automate the generation of an expanding flare animation with just a few lines of Scheme code.

The most interesting part of this implementation is the radius expression:

#:radius (+ (* 1 i) 100)

A simple mathematical calculation controls the visual evolution of the flare across multiple frames.

Once you understand this approach, you can apply the same technique to many other GIMP filters and effects. Instead of manually adjusting filter parameters frame by frame, you can write Script-Fu programs that generate entire sequences automatically.

The real power of Script-Fu is turning repetitive creative operations into reusable procedural graphics tools.