I'm looking to automate the addition of a small PNG at the centre of a much larger PNG using GIMP (2.8) and its Script-Fu language. The first image provided in the procedure call always shows, but the second image doesn't.
(overlay-images "/tmp/bigImage.png" "/tmp/smallImage.png" "/tmp/output.png")
Here is the script with the debugging I've been using to work out why the second image can't be seen in the output.png:
(define (overlay-images image-file-1 image-file-2 output-file)
(let* (
(image (car (file-png-load RUN-NONINTERACTIVE image-file-1 image-file-1)))
(drawable (car (gimp-image-get-active-layer image)))
(overlay-layer (car (gimp-file-load-layer RUN-NONINTERACTIVE image image-file-2)))
)
;; Add a debugging statement here
(gimp-message (string-append "overlay-layer: " (number->string overlay-layer)))
(gimp-image-add-layer image overlay-layer -1)
(gimp-message (string-append "Number of layers: " (number->string (car (gimp-image-get-layers image)))))
(gimp-message (string-append "Overlay layer visible: " (if (= (car (gimp-drawable-get-visible overlay-layer)) TRUE) "yes" "no")))
(let* (
(image-width (car (gimp-image-width image)))
(image-height (car (gimp-image-height image)))
(overlay-width (car (gimp-drawable-width overlay-layer)))
(overlay-height (car (gimp-drawable-height overlay-layer)))
(offset-x (/ (- image-width overlay-width) 2))
(offset-y (/ (- image-height overlay-height) 2))
)
(gimp-layer-set-offsets overlay-layer offset-x offset-y)
)
(let* (
(overlay-offsets (gimp-drawable-offsets overlay-layer))
(overlay-offset-x (car overlay-offsets))
(overlay-offset-y (cadr overlay-offsets))
)
(gimp-message (string-append "Overlay layer size: " (number->string (car (gimp-drawable-width overlay-layer))) "x" (number->string (car (gimp-drawable-height overlay-layer)))))
(gimp-message (string-append "Overlay layer position: (" (number->string overlay-offset-x) ", " (number->string overlay-offset-y) ")"))
)
(gimp-message (string-append "Number of layers before saving: " (number->string (car (gimp-image-get-layers image)))))
(gimp-message (string-append "Overlay layer visible before saving: " (if (= (car (gimp-drawable-get-visible overlay-layer)) TRUE) "yes" "no")))
(file-png-save RUN-NONINTERACTIVE image drawable output-file output-file 0 9 0 0 0 0 0)
(gimp-image-delete image)
)
)
My expectations are that the second image (smallImage.png) appears roughly in the centre of the first (bigImage.png). I've tried swapping the two images:
(overlay-images "/tmp/smallImage.png" "/tmp/bigImage.png" "/tmp/output.png")
That then shows smallImage.png in output.png so it isn't a file read error.
What am I missing?