GIMP - Script-fu
GIMP supports 2 scripting languages
The GIMP documentation has a decent tutorial
- Press F1 for help and select
- II. How do I Become a GIMP Wizard
- 13. Scripting
- 3. A Script-Fu Tutorial
However, there is no information on debug
(which is why I wrote this page).
Basics
| Errors loading the code
| Errors running the code
Basics
- Scripts are written using a text editor
- The file extension is - scm
- Comments start with a semicolon
- A list of all available functions is available via
- Script-fu is based on Lisp -
the language extensions (macros) are coded in
C:\Program Files\GIMP 2\share\gimp\2.0\scripts\script-fu.init
|
- All return values are lists - use car to get the first value
(even if there is only one value)
- Script examples are available at
C:\Program Files\GIMP 2\share\gimp\2.0\scripts\*.scm
|
- You should place your scripts in
C:\Documents and Settings\[username]\.gimp-2.8\scripts\script-fu-somename.scm
|
- Load your scripts via
Filters / Script-Fu / Refresh Scripts
|
It takes about 11 seconds (on my system) for the new menu options to appear
This is a basic template
; Explain why this file exists
;
; 07-xx-14 started file
; mm-dd-yy track changes with a date
;
(define (script-fu-make-icon inImage inDirName inFileName ) ; 3 arguments
; your code goes here
)
(script-fu-register
"script-fu-make-icon" ; function name
"Make Icon" ; menu label
"This line is shown in the status bar\
additional lines are shown in the\
pop-up help window." ; description
"Your Name" ; author
"Copyright 2014, Your Name" ; copyright notice
"July 2014" ; date created
"" ; image type that the script works on
SF-IMAGE "Image" 0 ; the arguments passed to the function
SF-DIRNAME "dirname" "/xyz"
SF-STRING "Filename" "test.ico"
)
(script-fu-menu-register "script-fu-make-icon"
; "<Image>/Tools/xyz") ; This is where I want it
"<Image>/Filters/xyz") ; This is just for test
|
For xyz, I use my initials .. so I know it is a script I wrote.
Errors loading the code
These errors occur when Refresh Scripts is selected.
Comments start with semicolons.
This error occurs when there is a colon where it should be a semicolon.
: 8) means that the error is in line 8.
|
|
Good
; creates duplicates of that layer
; scales and renames each - 48x48, 32x32, 16x16
|
Bad
; creates duplicates of that layer
: scales and renames each - 48x48, 32x32, 16x16
|
| |
|
The previous error would have been easier to find if the semicolon was just missing.
; creates duplicates of that layer
scales and renames each - 48x48, 32x32, 16x16
|
| |
|
This is the error shown when a closing parenthesis is missing.
| |
|
|
It is easy to miss this error - it occurs
for a short time in the status bar at the bottom of the image ..
then it disappears.
What it means is that there is an error in
script-fu-register and it has nothing to do with whether
a subroutine with that name exists!
script-fu-register requires 7 parameters - if it has 6 you get this error.
| |
Errors running the code
Once your code is loaded, you can locate and click on the menu selection.
At that time, a dialog box may be presented to load various parameters
(but only if some are defined).
These errors occur after you click OK
in the dialog box.
|
I counted the arguments many times - the number was identical ..
until I saw the extra space :(
When you are just starting, you never know what to believe.
The following should have 4 arguments - but actually has 5!
(define (script-fu-make-icon inImage inxxx
in DirName inFileName
)
|
| |
It appears that functions defined inside another function must be defined before they
are called.
However, functions can be defined in any order at the top level.
Most of the other errors I have seen are pretty straight forward and
easy to understand.
Author:
Robert Clemenzi