It is currently Wed Jun 17, 2026 11:44 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How do I script a new white layer to the bottom of the layer stack
PostPosted: Thu Nov 10, 2022 9:44 am  (#1) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 16
I'm a gimp script-fu beginner and have had a good search for this on google, with nothing coming up so far.

How do I script a new white layer that matches the size of the existing single layer and places this at the bottom of the current layer stack, underneath everything else.

It looks like it might be "gimp-layer-new", or something like that, from the procedure browser, but I have not been able to figure out a command that works.

I do this repeatedly and it makes sense to put this into a script and assign a keyboard shortcut.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: How do I script a new white layer to the bottom of the layer stack
PostPosted: Thu Nov 10, 2022 10:59 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
"gimp-layer-new" followed by "gimp-image-insert-layer", where the 4th argument is the count of layers -1.

Without scripting, there are some quick ways to move a layer to the bottom:

* Layer > Stack > Layer to bottom" (for which you can define a shortcut if necessary, see "Edit > Keyboard shortcuts")
* Shift-click the "V" icon at the bottom of the layers list.

_________________
Image


Top
 Post subject: Re: How do I script a new white layer to the bottom of the layer stack
PostPosted: Thu Nov 10, 2022 11:19 am  (#3) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 16
Thank you

I really don't get the command structure and have had a look

I put this

gimp-layer-new gimp-image-insert-layer 0 0 0 -1

Into the console and it did nothing

I've no idea whether that is the right format, or, what might go in place of the existing zeros.

I've found nothing that describes a white layer.

All that is wanted is what it does then you do this with the mouse


Top
 Post subject: Re: How do I script a new white layer to the bottom of the layer stack
PostPosted: Thu Nov 10, 2022 2:06 pm  (#4) 
You should learn Python, because GIMP python it's easier to write.
Go to Jackson Bates GIMP python tutorial site here: https://jacksonbates.wordpress.com/pyth ... ial-pages/

You will create a plugin script in no time.


Top
 Post subject: Re: How do I script a new white layer to the bottom of the layer stack
PostPosted: Thu Nov 10, 2022 8:35 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Dec 09, 2018
Posts: 734
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")


Top
 Post subject: Re: How do I script a new white layer to the bottom of the layer stack
PostPosted: Thu Nov 24, 2022 7:21 am  (#6) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 16
Pocholo wrote:
You should learn Python, because GIMP python it's easier to write.
Go to Jackson Bates GIMP python tutorial site here: https://jacksonbates.wordpress.com/pyth ... ial-pages/

You will create a plugin script in no time.


Thank you. I will do this when I have time. The pointer to the link appreciated.


Top
 Post subject: Re: How do I script a new white layer to the bottom of the layer stack
PostPosted: Thu Nov 24, 2022 7:22 am  (#7) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 16
ofnuts wrote:
"gimp-layer-new" followed by "gimp-image-insert-layer", where the 4th argument is the count of layers -1.

Without scripting, there are some quick ways to move a layer to the bottom:

* Layer > Stack > Layer to bottom" (for which you can define a shortcut if necessary, see "Edit > Keyboard shortcuts")
* Shift-click the "V" icon at the bottom of the layers list.


thank you


Top
 Post subject: Re: How do I script a new white layer to the bottom of the layer stack
PostPosted: Thu Nov 24, 2022 7:25 am  (#8) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 16
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.


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group