I have never learned / figured out / been pointed at an example
for how to properly write a script which is usable in both interactive 
and batch modes.

Let's say I have a script-fu add-on:

(define (add-watermark orgImg drw watermarkFileName relHt opacity)
...
)

(script-fu-register
  "add-watermark"
  "Add Watermark..."
  "Adds a scaled, partially transparent image to an image"
  "Gary Aitken"
  "Copyright 2013, Gary Aitken"
  "2013-08-28 v 0.1"
  ""
;  SF-MODE     "Mode"    "RUN-INTERACTIVE"  ; First arg is run mode
;  SF-STRING   "Main image file"    ""   ; name of main image to modify
  SF-IMAGE     "Image" 0                 ; main image to modify
  SF-DRAWABLE  "Drawable" 0              ; unused
  SF-STRING    "Added image file" "myfile.png" 
  SF-VALUE     "Relative (percent) height of added image"  "5"
  SF-VALUE     "Opacity of added image"  "50"
)

As written above, with the 
  SF-MODE    "Mode"    "RUN-INTERACTIVE"
  SF-STRING  "Main image file"  ""
arguments commented out, this script works in interactive mode,
operating on the active drawable in the active image;
the first two arguments to the function (orgImg and drw) are filled in 
automagically by the gimp when the script is activated.

The only way I have figured out how to use this from batch mode is to
add another script which contains the name of the base file to process:

(define (batch-add-watermark inFileName watermarkFileName outFileName relHt 
opacity)
  (let* (
      (orgImg (car (gimp-file-load RUN-NONINTERACTIVE inFileName inFileName)))
      (drw (car (gimp-image-get-active-layer orgImg)))
    )
    (add-watermark orgImg drw watermarkFileName relHt opacity)
    (gimp-file-save RUN-NONINTERACTIVE orgImg drw outFileName outFileName)
    (gimp-image-delete orgImg)
  )
)

This works, but neither procedure is making any use of what should be 
the first argument (missing from add-watermark above but present in 
batch-add-watermark) which is the mode.

My gut says the mode is there to make this all much easier, 
but I can't figure it out.  
Can someone give me a proper explanation of how to do this,
or point me at something?

Thanks,

Gary
_______________________________________________
gimp-user-list mailing list
List address:    gimp-user-list@gnome.org
List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list

Reply via email to