Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
script-fu - how to refer to the active image?
#2
(06-26-2020, 04:36 AM)stabilo Wrote: Hi, I'm a newbie. I can't figure out how to refer to the active image in a non-interactive script. The example scripts I find all refer to either a new image, or an image loaded from disk, or looping through the image list, or assuming you're working on the rightmost image, or the image comes as a parameter from the dialog (for interactive scripts). I haven't been successful in locating an example that just uses an already opened active image.

So if i have an image open and active, and I want a non-interactive script to reduce opacity of that selected image with a fixed amount  and then save the image, how do i refer to the image (and drawable)?


tnx!

Let's be clear on the vocabulary:
  • interactive: the user interacts with Gimp using the UI
  • non-interactive: Gimp is called from the command line with parameters defining an operation to execute, the UI oesn't even need to show up.
So, you are always in the "interactive" case, the question being whether or not the script pops up a dialog when called.

The secret is:
  • If the first parameter in your script is an image (SF_IMAGE in Scheme, PF_IMAGE in Python) then it is assumed to be the current image (in single window mode, the one in the active tab, in multiple windows mode, the one in the window where you used the menu). Since it is implicitly determined, the auto-generated dialog doesn't include a widget to select it.
  • If the second parameter is a "drawable" (a "drawable" is anything on which you can paint: layer, layer mask, or channel)(SF_DRAWABLE/PF_DRAWABLE) then it is assumed to be the current active drawable for the image: active layer or layer mask or channel. And here also, since it is implicitly determined, the auto-generated dialog doesn't include a widget to select it.
So if you create a script that just takes an image and a drawable (or just an image), the script executes right away without showing a dialog. In some cases, if you re-run the script (Ctr-shift-F),  it can need to ask for and image or drawable and you will get an auto-generated popup. And if you create a script that takes and image, a drawable, and an opacity, the dialog will only have a widget for the opacity.

Final note: you don't reduce the opacity of an image but the opacity of a layer in the image, so you will need both arguments.
Reply


Messages In This Thread
RE: script-fu - how to refer to the active image? - by Ofnuts - 06-26-2020, 05:42 AM

Forum Jump: