0

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.

Damien Cassou
  • 2,555
  • 1
  • 16
  • 21
  • If the plugin were that buggy many "official" scripts wouldn't work. Can't see anything obvious but was is the value of `image` after the file is loaded? – xenoid Nov 01 '22 at 08:27
  • @xenoid I answered by updating the original post. – Damien Cassou Nov 01 '22 at 09:09
  • Hmm where is the code that does the `gimp-image-set-active-layer`? – xenoid Nov 01 '22 at 09:38
  • @xenoid I gave you all of my code and there is nothing more in the `scripts/` directory. `script-fu-drop-shadow` calls `gimp-image-set-active-layer` 3 times. – Damien Cassou Nov 01 '22 at 10:27

1 Answers1

0

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)
xenoid
  • 8,396
  • 3
  • 23
  • 49
  • When I try `(script-fu-drop-shadow RUN-NONINTERACTIVE image drawable 20.0 20.0 10.0 '(0 0 0) 50 0)`, I get `Error: <: argument 1 must be: number`. – Damien Cassou Nov 01 '22 at 14:07
  • Only two uses of `<` in the code (`drop-shadow.scm`), both as ` (< (+ shadow-offset-x shadow-transl-x) 0)` so I don't see how the result of `(+ shadow-offset-x shadow-transl-x)` couldn't be a number. – xenoid Nov 01 '22 at 14:52