Search code examples
gimpscript-fu

Gimp batch open as layer


I encountered a Problem using gimp batch mode. All I am trying to do is to open 2 png files as layers of one image and save them together as an Icon (.ico).

Problem: Gimp just opens the two images as seperate windows, not as two images in one layer.

My code looks the following:

(define (merge-to-icon filename layername endname)
(
    let* 
    (
        (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
        (drawable (car (gimp-image-get-active-layer image)))
        (adlayer (car (gimp-file-load-layer RUN-NONINTERACTIVE image layername)))
    )
    (gimp-image-insert-layer image adlayer 0 0)
    (set! drawable (car (gimp-image-get-active-layer image)))
    (gimp-displays-flush)
    (gimp-file-save RUN-NONINTERACTIVE image drawable endname endname)
))

Solution

  • For non-interactive mode:

    (define (implode-imgs-save-ico fname-one fname-two)
        (let* (
                ; first main image
                (image (car (gimp-file-load RUN-NONINTERACTIVE fname-one fname-one)))
                ; them layer
                (drawable1 (car (gimp-image-get-active-drawable image)))
                ; open image as layer
                (drawable2 (car (gimp-file-load-layer RUN-NONINTERACTIVE image fname-two)))
            )
    
            ; add layer to image
            (gimp-image-insert-layer image drawable2 0 0)
    
            ;set layer mixing mode
            (gimp-layer-set-mode drawable2 SCREEN-MODE)
    
            ; may be some resize here
    
            ; merge layers
            (set! drawable (car (gimp-image-flatten image)))
    
            ; save
            (file-ico-save RUN-NONINTERACTIVE image drawable "my.ico" "my.ico")
        )
    )
    

    Then call it:

    gimp --no-interface --batch='(moo "back.png" "top.png")' -b (gimp-quit 0)