1

How to identify the latest selected image in gimp from gimp-image-list?

gimp-image-list returns a list with the number of images as first element and a vector of image-ids as the second element.

In case there is more than one image, how is it possible to find the last focused one?

Gyro Gearloose
  • 1,056
  • 1
  • 9
  • 26

2 Answers2

3

You don't. The order in the list is the reversed order in which images were open - which is usually the reversed orders on the image tabs.

What happens is that if you write a script that is supposed to affect an open image, you should put it in the "" menu - that way GIMP will pass you the active image and active drawable as first parameters "for free" (that is, without requiring the user to select them).

On interactive mode, - i.e. outside a script you just check the image ID on the title bar.

jsbueno
  • 99,910
  • 10
  • 151
  • 209
  • Thank you for your answer. I would accept it but I like to wait some time to see if someone comes around with something to iterate through the image Ids to find out the latest one active ---- it must be possible because, as you confirm, gimp keeps track of the active image. – Gyro Gearloose Apr 18 '16 at 17:06
0

You need to define the image and drawable area when registering your script. For example:

(script-fu-register "script-fu-some-handy-function"
_"_Handy function..."
_"Does something handy for your image."
"Michael T <username@domain.com>"
"Michael T"
"24/09/2022"
"*"
SF-IMAGE       "Input image" 0
SF-DRAWABLE    "Input drawable" 0
)

Then, when you need to use the image, you will just type "image" to use the referenced image.

(define (script-fu-some-handy-function image drawable)

    (define width (car(gimp-image-width image)))
    (define height (car(gimp-image-height image)))  

    (define newLayer (gimp-layer-new image width height 1 "Black" 100 0))
    (define newLayerIndex (car newLayer))
    (gimp-image-insert-layer image newLayerIndex 0 0)
    (gimp-context-set-foreground '(0 0 0))
)

Notice how we define the variable in the function definition, otherwise that variable won't work within the definition.

MikeJT
  • 1