Search code examples
ubuntucommand-line-interfacegimp

Why doesn't work the GIMP-script in CLI mode?


I wrote a GIMP-Script that works if I open it via the button in the GIMP-GUI but doesn't work if I try to start it in the CLI Mode(on Ubuntu). I tried the following command:

 gimp -c -i -d -b '(documentEnhancementProcedure 1 "raw.png" "test.png")' -b '(gimp-quit 0)'

and get the Error: "Invalid type for argument 2 to file-png-load".

Since the script works, when i start it from the GIMP-GUI I think it's a problem with the CLI command.

I have tried:

  • full filepaths
  • escape characters

I think it's propably a small mistake, but I'm currently not able to spot it...

Thank you in advance for your help!

The script:

(define (documentEnhancementProcedure infile outfile)
   (let*
        (
        (image (car (file-png-load 1 infile infile)))
        (drawable (car (gimp-image-get-active-drawable image)))

        (image-width (car (gimp-image-width image)))
        (image-height (car (gimp-image-height image)))

    )
    ;1. scale image by the factor 2
    (gimp-image-scale image
          (* image-width 2) (* image-height 2))
        ; (* image-width 2) New image width (1 <= new-width <= 524288)
        ;                   (* image-height 2) New image height (1 <= new-height <= 524288)


    ;2 apply sharpen-filter with given variables
    (plug-in-unsharp-mask 1 image drawable
          3 0.4 0)
        ; 3 Radius of gaussian blur (0 <= radius <= 300)
        ;   0.4 Strength of effect (0 <= amount <= 300)
        ;       0 Threshold (0 <= threshold <= 255)


    ;3.save image as png
    (file-png-save2 1 image drawable outfile outfile
          1 0 0 0 0 0 0 0 0 )
        ; 1 Adam7 interlacing?
        ;   0 deflate compression factor (0-9)
        ;     0 Write bKGD chunk?
        ;       0 Write gAMMA chunk?
        ;         0 Write oFFs chunk?
        ;           0 Write pHYS chunk?
        ;             0 Write tIME chunk?
        ;               0 Write comment?
        ;                 0 Preserve color of transparent pixels?

   )
)

(script-fu-register
    "documentEnhancementProcedure"                   ; script name to register
    "<Toolbox>/Xtns/Script-Fu/ownScripts/documentEnhancementProcedure" ; where it goes
    "document gets doubeld in size\
    and sharpened with following sharpen variables:\
    radius 3\
    amount 0.4\
    threshold 0"                                     ; script description
    ""                                               ; author
    "Copyright 2021 by; GNU GPLv3"                   ; copyright
    "23.09.2021"                                     ; date
    ""                                               ; type of image
    SF-FILENAME "Infile" "infile.png"                ; default parameters
    SF-FILENAME "Outfile" "outfile.png"
)

Solution

  • The comment by @xenoid worked:

    Try omitting the RUN-MODE argument. Btw, 1) you don't need to register the script if you use it in batch mode, and 2) you can do the very same thing in one line using ImageMagick's convert command (see -geometry and -sharpen args).