Script fu 'unbound variable' error on arguments - gimp

So i tried to run the batch code from this tutorial: http://www.gimp.org/tutorials/Basic_Batch/
I copied and saved this to the .gimp-2.8 scripts folder
(define (batch-unsharp-mask pattern
radius
amount
threshold)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE
filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(plug-in-unsharp-mask RUN-NONINTERACTIVE
image drawable radius amount threshold)
(gimp-file-save RUN-NONINTERACTIVE
image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))
And ran the command:
gimp-2.8 -i -b '(batch-unsharp-mask "*.png" 5.0 0.5 0)' -b '(gimp-quit 0)'
But i get the error
Error: ( : 1) eval: unbound variable: *.png
This doesn't seem to be a problem with the script; probably the way i am calling it or i am missing something but i cant figure it out.

I know it's been four long months, but I was just fighting with a gimp (2.8) script I had written and getting a recurring
batch command experienced an execution error:
Error: ( : 32578) eval: unbound variable: while
It turns out that, in my haste to consolidate script directories, I had removed the reference to /usr/share/gimp/2.0/scripts. Apparently there's something in that directory that defines "while"
Edit->Preferences->Folders->Scripts

Got the original script working in gimp 2.8 ubuntu 14.04lts Just had to copy and paste the line breaks back together. I am having trouble pasting this in so the lines are not broken, just remove the blank lines as they are a posting anomaly. Place script in ~/.gimp-2.9/scripts
Using this to remove haze
run as gimp -i -b '(batch-unsharp-mask "*.JPG" 100 0.3 0)' -b '(gimp-quit 0)'
(define (batch-unsharp-mask pattern radius amount threshold)
(let* ((filelist (cadr (file-glob pattern 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
(drawable (car (gimp-image-get-active-layer image))))
(plug-in-unsharp-mask RUN-NONINTERACTIVE image drawable radius amount threshold)
(gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
(gimp-image-delete image))
(set! filelist (cdr filelist)))))

I resolved this error by confirming the name of my script. I copied my script from an existing script and the name was duplicate. After I updated the name of my script the error went away and everything started working.
You must have unique script names, that includes the define name

What helped me was making sure that the script had the correct extension, .scm.

Related

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

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.
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)

Script not using defined path

Sorry for any errors, english is not my native language
I'm in need of a certain script to manipulate a bunch of images, to not bother people to death by asking "can someone do this for me?", i'm trying to learn how to write them myself.
I start by creating a script that will move images from one folder to another, from /Images/origin to /Images/destination, I need this to be a relative path since i need it to work anywhere as long as theres a origin and destination folder inside a Images folder.
Currently I have the next script (taken from what i could learn, copy and understand) but when saving an image it doesn't save where i expect it to go, actualy it does nothing.
(define (batch-move)
(let* (filelist (cadr (file-glob "/Image/origin/*.png" 1))))
(while (not (null? filelist))
(let* ((filename (car filelist))
(image (car (gimp-file-load RUN-NONINTERACTIOVE filename filename)))
(draw (car (gimp-image-get-active-layer image)))
(gimp-file-save RUN-NONINTERACTIVE image draw filename/../destination filename)
(set! filelist (cdr filelist))
))))
The place where is the function(?) gimp-file-save, i've tried to put the path before, and in this example after, but it doesn't work.
This is assuming the filename is the complete path using /../ to go back a folder and /destination/ go to the next, same way as to navigate windows using relative path directories
I also understand that the gimp-image-get-active-layer is probably not necessary but this is for me to later add all the functions that i need.
And my question is why is it not working?, from what I gather the filename variable is the entire path, but if it isn't then what is is?

script-fu variables set from cond but treated as unset

I'm trying to set up a script for raw photos, to allow me to add two copies of the existing file (all taken from ufraw), at different exposures so I can recover shadow and highlight detail. The part for the shadow file is now working, hard-coded to use the same layer for its mask and with a mode of NORMAL.
But I want to pass an option for the shadow mask, so that I can take it from the shadow layer or the base layer (the normal exposure) AND set the mode to NORMAL or LIGHTEN-ONLY. The following code does not error:
(cond ( < shadow-option 2 ) (define (sm-source shadow-layer))
(else (define (sm-source base-layer))))
(cond ( = shadow-option 0 ) (define (shadow-mode NORMAL))
(else (define (shadow-mode LIGHTEN-ONLY))))
Maybe my cond tests are not going to do what I want, but AFAICS both sm-source and shadow-mode must have a value, either from the test being true, or from the else ?
But both appear to not be defined when I try to reference them. The first use is on the next line of my script:
(gimp-layer-set-mode shadow-layer shadow-mode)
But I get Error: ( : 1) eval: unbound variable: shadow-mode. If I comment that line and replace it by a hardcoded mode, I then get a similar error for sm-source.

script-fu script not load image under gimp 2.0

I try to make working this script with gimp 2.8 .
I don't see script-fu-register in Procedure Browser).
I try running with RUN-INTERACTIVE and RUN-NONINTERACTIVE... this script:
(define (script-fu-cut-height filename outputfilename myheight)
(let* (
(img (myimage (gimp-file-load RUN-INTERACTIVE filename filename)))
(imagewidth (myimage (gimp-image-width img)))
(imageheight (myimage (gimp-image-height img)))
(width (- imagewidth (+ right left)))
(height (- myheight (+ top bottom)))
)
(gimp-image-crop img width height left top)
(gimp-png-save RUN-INTERACTIVE
img
(myimage (gimp-image-active-drawable img))
outputfilename
outputfilename)
(gimp-image-delete img)
))
(script-fu-register "script-fu-cut-height"
"www.free-tutorials.org : script-fu"
"Cut an image by height and let width default"
"test"
"www.free-tutorials.org"
"Jul 2013"
"RGB* GRAY*"
SF-STRING "Filename" ""
SF-STRING "OutputFilename" ""
SF-VALUE "TopEdge" "0"
SF-VALUE "RightEdge" "0"
SF-VALUE "BottomEdge" "0"
SF-VALUE "LeftEdge" "0"
)
script-fu-cut-height()
I use this to run it :
$ gimp -i -c -b "(script-fu-cut-height \"test-script-fu.png\" \"out-script-fu-output.png\" 85)" -b "(gimp-quit 0)"
The image it's on user home folder .
The error I got :
~$ gimp -i -c -b "(script-fu-cut-height \"test-script-fu.png\" \"out-script-fu- output.png\" 85)" -b "(gimp-quit 0)"
Fontconfig warning: "/etc/fonts/conf.d/65-droid-sans-fonts.conf", line 103: Having multiple values in <test> isn't supported and may not work as expected
Fontconfig warning: "/etc/fonts/conf.d/65-droid-sans-fonts.conf", line 138: Having multiple values in <test> isn't supported and may not work as expected
batch command experienced an execution error:
Error: (<unknown> : 136051114) eval: unbound variable: myimage
Fontconfig warning: "/etc/fonts/conf.d/65-droid-sans-fonts.conf", line 103: Having multiple values in <test> isn't supported and may not work as expected
Fontconfig warning: "/etc/fonts/conf.d/65-droid-sans-fonts.conf", line 138: Having multiple values in <test> isn't supported and may not work as expected
The error says "unbound variable: myimage". This is telling you that you are referring to a variable/function called "myimage," but you never defined that variable, so it doesn't know what "myimage" represents.
Do you know what "myimage" is supposed to represent? Did you copy that from another person's script?
The function gimp-file-load returns a list containing the image that you opened. You need to use the "car" function to extract the first entry from that list, so that it can be stored in your "img" variable. So instead of
(img (myimage (gimp-file-load RUN-INTERACTIVE filename filename)))
it should say
(img (car (gimp-file-load RUN-INTERACTIVE filename filename)))
Also, I think you might want to use RUN-NONINTERACTIVE instead.
Similarly, I think you will need to change each other instance of
(my image ...)
to be
(car ...)
instead.

Does such a procedure exist in a Scheme standard and if yes, how is it called?

I looked for the name of a procedure, which applies a tree structure of procedures to a tree structure of data, yielding a tree structure of results - all three trees having the same structure.
Such a procedure might have the signature:
(map-tree data functree)
Its return value would be the result of elementwise application of functree's elements on the corresponding data elements.
Examples (assuming that the procedure is called map-tree):
Example 1:
(define *2 (lambda (x) (* 2 x)))
; and similar definitions for *3 and *5
(map-tree '(100 (10 1)) '(*2 (*3 *5)))
would yield the result (200 (30 5))
Example 2:
(map-tree '(((aa . ab) (bb . bc)) (cc . (cd . ce)))
'((car cdr) cadr))
yields the result ((aa bc) cd)
However I did not find such a function in the SLIB documentation, which I consulted.
Does such a procedure already exist?
If not, what would be a suitable name for the procedure, and how would you order its arguments?
I don't have a very good name for the function. I'm pasting my implementation below (I've called it map-traversing; others should suggest a better name). I've made the argument order mirror that of map itself.
(define (map-traversing func data)
(if (list? func)
(map map-traversing func data)
(func data)))
Using your sample data, we have:
(map-traversing `((,car ,cdr) ,cadr) '(((aa . ab) (bb . bc)) (cc cd . ce)))
The second sample requires SRFI 26. (Allows writing (cut * 2 <>) instead of (lambda (x) (* 2 x)).)
(map-traversing `(,(cut * 2 <>) (,(cut * 3 <>) ,(cut * 5 <>))) '(100 (10 1)))
The most important thing is that your functions must all be unquoted, unlike your example.
I found that with the follwing definition of map-traversing, you don't need to unquote the functions:
(define (map-traversing func data)
(if (list? func)
(map map-traversing func data)
(apply (eval func (interaction-environment)) (list data))))
Note: in my installed version of Guile, due to some reason, only (interaction-environment) does not raise the Unbound variable error. The other environments i.e. (scheme-report-environment 5) and (null-environment 5) raise this error.
Note 2: Subsequently, I found in [1] that for (scheme-report-environment 5) and (null-environment 5) to work, you need first to (use-modules (ice-9 r5rs))
[1]: http://www.mail-archive.com/bug-guile#gnu.org/msg04368.html 'Re: guile -c "(scheme-report-environment 5)" ==> ERROR: Unbound variable: scheme-report-environment'

Resources