I have several set of images with a fixed background and an object moving in the foreground. I'd like to get an idea of the motion of the object by superimposing images with scaled opacity.

If I load a single bunch of N images into GIMP as N distinct layers, is there a way to automatically set the opacity of all the layers to get a scale effect from the first with P1% (e.g. 0% opacity) to the last with P2% (e.g. 100% opacity)?

  • Hi alextoind, thanks for your question. Could you tell us what you tried that didn't work? Did you Google around for scripts? Always good to show some effort, and your chances for a good answer increase. If you have any questions, please see the help center or ping one of us in the Graphic Design Chat once your reputation is sufficient (20). Keep contributing and enjoy the site!
    – PieBie
    Jan 4 '16 at 13:31

It is feasible from the Python Console window. Opacity is a layer property, so it is possible to set it with a simple attribution.

Go to filters->Python Fu->Console - there you can type Python expressions. The first one you want is to get a reference to your image - for example: img = gimp.image_list()[0] (press enterafterwards) will get you a reference to the latest (rightmost tab) open image in GIMP. (increase the numbers from 0 inside the brackets to get to the other images)

The layers are available as a Python list when you type img.layers, and the opacity varies from 0.0 to 100.0 - so, the first thing to do is to calculate how much you want to increase the opacity from one layer to the next - that number is: opacity_step = 100.0 / (len(img.layers) - 1) (just type the variable names, like img and opacity_step by themselves and press enter to check their values). Now, just pick a starting opacity - ex. current_opacity = 0.0 and then iterate over all layers with a for command, setting the opacity. So, putting everything together, you should type:

img = gimp.image_list()[0]
opacity_step = 100.0 / (len(img.layers) - 1)
current_opacity = 0.0
for layer in reversed(img.layers):
    layer.opacity = current_opacity
    current_opacity += opacity_step
  • Awesome! I didn't even know about the Python console inside GIMP (:shy:), and this changes everything. Many thanks!
    – alextoind
    Jan 5 '16 at 21:34
  • There is a little mistake: it should be opacity_step = 100.0 / (len(img.layers) - 1) to cover the whole range, but it works like a charm!
    – alextoind
    Jan 5 '16 at 21:43
  • 1
    Oh well...off by one errors are one of those two things that never go away. Fixed in the example.
    – jsbueno
    Jan 6 '16 at 3:26
  • Shouldn't it check for > 2 layers (and do nothing for <= 2 layers), and take the opacity of the upper and lowermost layers into account as well? At least that's how I read the question, albeit the changes required for this are trivial. Jan 7 '16 at 15:11
  • This answer is not a complete plug-in code, it is rather a guide for for the O.P. to type interactively at the interactive prompt. If it where a proper plug-in, then some more lines checking for corner cases, and even more options would be easy to add.
    – jsbueno
    Jan 7 '16 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.