Get error on 'gimp-image-set-active-layer' when trying to use script-fu-drop-shadow

244 views Asked by At

I would like to add a drop shadow to picture files without using the Gimp UI. I've saved this content to ~~/.config/GIMP/2.10/scripts/my.scm~:

(define (my/add-drop-shadow filename)
  (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
         (drawable (car (gimp-image-get-active-layer image))))
    ;; Apply transformations
    (script-fu-drop-shadow RUN-NONINTERACTIVE image drawable
                            20.0 20.0 10.0 0 0.5 nil)))

(I know this code is not saving the image, I will add that when this works).

Unfortunately, when trying to use that, I get an error:

$ gimp --version
2.10.30

$ gimp -i -b '(my/add-drop-shadow "2022-11-01-080429.png")' -b '(gimp-quit 0)'
GIMP-Error: Calling error for procedure 'gimp-image-set-active-layer':
Procedure 'gimp-image-set-active-layer' has been called with an invalid ID for argument 'active-layer'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer.

batch command experienced an execution error:
Error: Procedure execution of gimp-image-set-active-layer failed on invalid input arguments: Procedure 'gimp-image-set-active-layer' has been called with an invalid ID for argument 'active-layer'. Most likely a plug-in is trying to work on a layer that doesn't exist any longer. 

/home/cassou/.nix-profile/bin/gimp: GEGL-WARNING: (../gegl/buffer/gegl-tile-handler-cache.c:1076):gegl_tile_cache_destroy: runtime check failed: (g_queue_is_empty (&cache_queue))
EEEEeEeek! 2 GeglBuffers leaked

Am I doing something incorrect or is the plug-in buggy?

Update

If I add these statements to the script at the start of the let body:

(print "=============================")
(print image)
(print drawable)
(print "=============================")

I get:

"============================="
1
2
"============================="

as output.

1

There are 1 answers

2
xenoid On

No a script-fu expert but at least 3 problems in your call:

  • The "color" argument isn't just an integer (at least in a full-RGB image), most likely a triplet, or the result of (gimp-context-get-foreground)
  • The opacity is a 0-100 number, with .5 you won't see much, you probably want 50 instead
  • The resizing argument should be 0 or 1

Calling from python this works:

pdb.script_fu_drop_shadow(image, image.active_layer,20.0, 20.0, 10.0, (0,0,0), 80, 0)