stryker wrote:I've found that a call to gimp-image-get-filename will crash the script-fu if there is no open image. To avoid this, I want to test that there is a value in the parameter img which is being passed.
In the general case, it should not be necessary to test for a valid image because either your script creates the image or the image is passed to your script as an SF-IMAGE argument (in the 'script-fu-register' procedure).
Of particular note with regard to 'script-fu-register' is the seventh parameter, which is the menu constraint specification. This parameter is string specifying when your command will be accessible in the menus and represents a test for the colorspace of currently active drawable. If the colorspace of the active drawable does not match the value of the seventh argument, the menu command will be disabled. Possible values are currently "RGB", "RGBA", "GRAYSCALE", "GRAYSCALEA", "INDEXED", and "INDEXEDA". Multiple colorspaces can be supported by appending the above strings separated by commas, by using an asterisk as a wildcard character, or a combination of the two (e.g., "RGB*,GRAY*" would make the command available unless the images is in INDEXED mode).
If your script is able to work on any type of drawable, your constraint specification string should "*" (which is equivalent to "RGB,RGBA,GRAYSCALE,GRAYSCALEA, INDEXED,INDEXEDA").
Importantly, if your constraint parameter is the empty string ("") then your script does not expect an image at all (and there should not be a SF-IMAGE declaration in the PDB parameter list). This option should be employed when your script creates its own image(s) from scratch (see the scripts under "File->Create" for examples), or your script is doing something other than manipulating images (for example, generating a gradient or palette).
Note that if your script is registered with a constraint that is anything but the empty string, there is no way the user can invoke your script without there being a valid image available. Thus it is typically not necessary to test for the validity of the image.
Nonetheless, if you do wish to test for the validity of your image, paynekj's suggestion offers a safe way of doing so (but I'd advise that you double-check the necessity of doing such).