teapot wrote:
kes,
I think the position you want for the bottom of the layer stack is the count of layers. Not the count of layers -1.
Agree with the above that Python is easier to write so worth switching to that, but since you are already using scheme below is a simple go at the basics.
If you are using layer groups you may want the background layer at the bottom of the group instead. Also you may want the original active layer made active again.
(define (script-fu-add-background-layer image drawable)
(gimp-image-undo-group-start image)
(let* ((width (car (gimp-drawable-width drawable)))
(height (car (gimp-drawable-height drawable)))
(num-layers (car (gimp-image-get-layers image)))
(background-layer (car (gimp-layer-new image width height RGBA-IMAGE "Background" 100 LAYER-MODE-NORMAL)))
(offsets (gimp-drawable-offsets drawable))
(offx (car offsets))
(offy (cadr offsets)))
(gimp-drawable-fill background-layer FILL-WHITE)
(gimp-image-insert-layer image background-layer 0 num-layers)
(gimp-layer-set-offsets background-layer offx offy))
(gimp-image-undo-group-end image)
(gimp-displays-flush))
(script-fu-register
"script-fu-add-background-layer" ; Name
"Add a background layer" ; Menu label
"Add a white layer at the bottom of the layer stack." ; Description
"Author" ; Author
"Copyright" ; Copyright
"Nov 2022" ; Date
"*" ; Types
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
)
(script-fu-menu-register "script-fu-add-background-layer" "<Image>/Layer")
Thank you. Really appreciated. Saved me a tonne of time with a very repetitive task across many many files, where I had to add a white layer to the lowest part of the layer stack.
Script-fu seems convoluted though I am sure it is not if you have time to get into it.
I can see at some time I will have to learn python gimp scripting, when I get a moment.