RSS/Atom feed Twitter
Site is read-only, email is disabled

First script-fu advice

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

5 of 6 messages available
Toggle history

Please log in to manage your subscriptions.

First script-fu advice john 29 Apr 16:42
  First script-fu advice Jeff Trefftzs 29 Apr 18:51
   First script-fu advice John Keniry 29 Apr 21:16
john@ice-nine.co.uk 07 Oct 20:15
  First script-fu advice Jeff Trefftzs 29 Apr 21:51
   First script-fu advice John Keniry 30 Apr 00:33
john
2002-04-29 16:42:05 UTC (almost 22 years ago)

First script-fu advice

I've just made my first short script and would like to finish it by leaving the layers, channels and paths dialog open at the end so that the user can manipulate the opacity slider, flatten the image, or if they don't like the effect at all, delete the layer created by the script.

Is there a way to do this?

If thats not possible, could I display a message at the start of the script explaining that they should open the layers dialog after the script is run?

Erhm might as well include the script... any advice welcome...

; contrast-mask.scm ;
; A gimp script to adjust contrast levels in photographs, ; reducing highlights and brightening shadows

(define (script-fu-contrast-mask img drawable)

; Create a new layer to hold the contrast mask (set! mylayer (car (gimp-layer-copy drawable 0)))

; Name the layer (gimp-layer-set-name mylayer "Contrast Mask")

; Add the layer to the image (gimp-image-add-layer img mylayer 0)

; Set the draw mode to overlay (gimp-layer-set-mode mylayer 5)

; Desaturate the layer (gimp-desaturate mylayer)

; Invert the colours (gimp-invert mylayer)

; Blur the layer by a huge amount (plug-in-gauss-rle 1 img mylayer 94 1 1)

; Flush the display (gimp-displays-flush)
)

(script-fu-register "script-fu-contrast-mask" "/Script-Fu/local/contrast-mask" "Create a contrast mask in a new layer. Open the layers dialog after running the script to adjust the opacity and flatten the image" "John Keniry"
"John Keniry"
"April, 2002"
"RGB*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Layer" 0
)

Jeff Trefftzs
2002-04-29 18:51:24 UTC (almost 22 years ago)

First script-fu advice

Hi John -

It doesn't look like there is any way to call up a dialog box from inside a script, but that shouldn't matter, since Real Gimpers (tm) always have the layers and channels dialog box open anyway ;-)

A suggestion: Whenever possible, use the symbolic names rather than the absolute numbers for the modes (e.g., (gimp-layer-set-mode mylayer OVERLAY-MODE) instead of (gimp-layer-set-mode mylayer 5) ). Makes things easier to read and understand. You can always check if the symbolic name is right by typing it into the Script-Fu Console, where it will give you back the numeric value.

For the Mark II version, you might want to add a toggle to allow automatic flattening, and maybe a SF_ADJUSTMENT to allow the user to set transparency when the script is called.
(And maybe another adjustment to specify the blur radius?).

John Keniry
2002-04-29 21:16:07 UTC (almost 22 years ago)

First script-fu advice

Hi Jeff

On Monday 29 April 2002 17:51 pm, Jeff Trefftzs wrote:

A suggestion: Whenever possible, use the symbolic names rather than the absolute numbers for the modes (e.g., (gimp-layer-set-mode mylayer OVERLAY-MODE) instead of (gimp-layer-set-mode mylayer 5) ).

Aha! I didn't know there was a symbolic name, in fact I only guessed at the numeric value by counting the menu items in the mode menu.

For the Mark II version, you might want to add a toggle to allow automatic flattening, and maybe a SF_ADJUSTMENT to allow the user to set transparency when the script is called. (And maybe another adjustment to specify the blur radius?).

Ok I've incorporated these into the script. To be honest the blur radius is hardly worth changing from the default IMO, but the option is there. I made automatic flattening default to FALSE for safety's sake, and I've also included the undo functions for a little extra useability.

I've been manually applying this technique to my photographs for months, promising myself I would check out script-fu but never getting around to it. Wish I'd done this sooner - its so easy!
Thanks for making suggestions that made me learn a little more :-)

The Mark II version...

; contrast-mask.scm ;
; A gimp script to adjust contrast levels in photographs, ; reducing highlights and brightening shadows ;

(define (script-fu-contrast-mask img drawable opacity blurring flatten)

; Start the undo group (gimp-undo-push-group-start img)

; Create a new layer to hold the contrast mask (set! mylayer (car (gimp-layer-copy drawable 0)))

; Name the layer (gimp-layer-set-name mylayer "Contrast Mask")

; Add the layer to the image (gimp-image-add-layer img mylayer 0)

; Set the draw mode to overlay (gimp-layer-set-mode mylayer OVERLAY-MODE)

; Desaturate the layer (gimp-desaturate mylayer)

; Invert the colours (gimp-invert mylayer)

; Blur the layer (plug-in-gauss-rle 1 img mylayer blurring 1 1)

; Set the opacity of the layer (gimp-layer-set-opacity mylayer opacity)

; Optionally flatten the image (if (= flatten TRUE) (gimp-image-flatten img))

; Handle undo (gimp-undo-push-group-end img)

; Flush the display (gimp-displays-flush)

)

(script-fu-register "script-fu-contrast-mask" "/Script-Fu/local/contrast-mask" "Create a mask in a new layer to improve contrast in photographs." "John Keniry"
"John Keniry"
"April, 2002"
"RGB*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Layer" 0
SF-ADJUSTMENT "Mask opacity" '(100 0 100 1 20 0 0) SF-VALUE "Mask blurring" "94"
SF-TOGGLE "Flatten layers" FALSE )

Jeff Trefftzs
2002-04-29 21:51:57 UTC (almost 22 years ago)

First script-fu advice

Hi John -

Something else I have found invaluable is the PDB explorer. You need to have perl installed when you compile the GIMP to get this, but it's worth the trouble. It gives you access to all of the exported GIMP function calls, tells you their parameters, and even (often) gives the symbolic names of the parameter values.

Nice, useful script, btw.

John Keniry
2002-04-30 00:33:35 UTC (almost 22 years ago)

First script-fu advice

Hi Jeff

On Monday 29 April 2002 20:51 pm, you wrote:

Something else I have found invaluable is the PDB explorer. You need to have perl installed when you compile the GIMP to get this, but it's worth the trouble. It gives you access to all of the exported GIMP function calls, tells you their parameters, and even (often) gives the symbolic names of the parameter values.

Right, that comes as a separate package in Debian.

Nice, useful script, btw.

The basic idea comes from a photoshop tutorial I saw ages ago. After I had done it by hand a few times it was obvious it should be automated but I just never got around to it. The technique won't improve every photograph but I think its worth trying whenever you have contrast problems because sometimes the improvement can be suprising.