I'm new to Script-Fu and am trying to write a script which takes in a layer name and color and recolors all black pixels in that layer the specified color. My code is below. I register it using script-fu-register and calling it from within the graphic interface. When I try to run it, I get the illegal function error. It seems to be something related to gimp-image-get-layer-by-name (when I comment out that part, the function that is supposed to save the file as a png runs fine). Would be very grateful for any suggestions!
(define (script-fu-recolor-layer image color layername imgoutname)
(gimp-image-undo-group-start image)
(gimp-selection-none image)
(gimp-context-set-foreground color)
(gimp-message (number->string (car (gimp-image-get-layer-by-name image layername))))
(let*
(
(activelayer (car (gimp-image-get-layer-by-name image layername)))
)
(
(gimp-image-select-color image 0 activelayer '(0 0 0))
(gimp-edit-bucket-fill activelayer FG-BUCKET-FILL NORMAL-MODE 100 0 0 0 0)
(gimp-item-set-visible activelayer 1)
)
)
; source: https://stackoverflow.com/questions/49922377/how-to-export-flattened-image-with-gimp-script-fu
(let* (
(duplicateImg (car (gimp-image-duplicate image) ) )
)
(let* (
(flatLayer (car (gimp-image-flatten duplicateImg) ) )
)
(
(file-png-save 1 duplicateImg flatLayer imgoutname imgoutname 1 0 0 0 0 0 0)
)
)
)
(gimp-image-undo-group-end image)
(gimp-displays-flush)
)