It is currently Thu Sep 17, 2026 9:29 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: SF-TOGGLE question
PostPosted: Sun Jul 29, 2012 5:30 pm  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
So I want to create the option to ignore a certain chunk of the script. For the purpose of asking this question, I've written a basic script below that converts the image to gray scale, changes the threshold based on a user defined input, increase the canvas size, adds a new layer and adds a simple blur effect.

I want to have the option of skipping the hurl & blur effect (Boarder effect). I am guessing that SF-TOGGLE would be used, but I really have no clue how I would write the script. I've looked at other scripts, but I couldn't find anything simple that would help me figure this out.

Any input is greatly appreciated.

(define (script-fu-threshold-boarder image drawable threshold)

(let*

(
(width (car (gimp-image-width image)))
(height (car (gimp-image-height image)))
(boarderLayer)
(nwhCal (* width 0.05))
(newWidth (+ width nwhCal))
(newHeight (+ height nwhCal))
(xyoff (* nwhCal 0.5))
(x-center (* newWidth 0.5))
(y-center (* newHeight 0.5))
)


(gimp-image-convert-grayscale image)

;Apply user defined threshold settings
(gimp-threshold drawable threshold 255)

;Canvas resize for boarder
(set! imageCanvas (car (gimp-image-resize image newWidth newHeight xyoff xyoff)))
(set! drawable (car (gimp-image-get-active-drawable image)))

;New layer
(set! boarderLayer (car (gimp-layer-new image newWidth newHeight GRAYA-IMAGE "Boarder Layer" 100 NORMAL-MODE)))
(gimp-image-insert-layer image boarderLayer 0 +1)
(gimp-drawable-fill boarderLayer BACKGROUND-FILL)

;Boarder effect
(plug-in-randomize-hurl RUN-NONINTERACTIVE image boarderLayer 1 1 1 FALSE)
(plug-in-mblur RUN-NONINTERACTIVE image boarderLayer LINEAR 20 0 x-center y-center)

)

)

(script-fu-register "script-fu-threshold-boarder"
"<Image>/Filters/Threshold &/or Boarder"
"Threshold &/or Boarder"
"PD"
"PD"
"July 2012"
"RGB* Gray*"
SF-IMAGE "image" 0
SF-DRAWABLE "drawable" 0
SF-ADJUSTMENT "Threshold" '(70 40 100 1 10 1 0)
)

Thank you!


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: SF-TOGGLE question
PostPosted: Mon Jul 30, 2012 1:24 am  (#2) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Yes, SF-TOGGLE is what you want for this sort of flag.

So in your register block you would put something like:
SF-TOGGLE _"Do other stuff" TRUE


The procedure define line would be
(define (script-fu-threshold-boarder image drawable threshold do_other_stuff)


Then in your code you could put
        (if (= do_other_stuff TRUE)
          (begin
             ; code to do if selected
             ;Border effect
             (plug-in-randomize-hurl RUN-NONINTERACTIVE image boarderLayer 1 1 1 FALSE)
             (plug-in-mblur RUN-NONINTERACTIVE image boarderLayer LINEAR 20 0 x-center y-center)
          )
          (begin  ; This is the optional 'else' case i.e. code to do if not selected
          )
        )


Kevin


Top
 Post subject: Re: SF-TOGGLE question
PostPosted: Mon Jul 30, 2012 2:22 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
Thank you Kevin. Worked perfectly.

I started working on something similar before I read your post, but for some reason I can't get it to work. It is so simple, yet I always get an error that the procedure has been called with an invalid ID for the argument 'image'. I'm a little perplexed because the script does nothing to the image until the 'begin'.

(define (image-convert-greyscale-pd image drawable effect)

(if (= effect TRUE)
(begin

(gimp-image-convert-grayscale image)
(gimp-displays-flush)

)

(begin

)
)
)

(script-fu-register "image-convert-greyscale-pd"
"<Image>/Filters/PD grayscale"
"convert to greyscale."
"PD"
"PD"
"July 2012"
"RGB* GRAY*"
SF-IMAGE "Image" 0
SF-DRAWABLE "Drawable" 0
SF-TOGGLE "Effect" TRUE
)

I'm really new to this, but this looks like it should work. I'm just trying to better understand the procedure so I can put it to work in other scripts.


Top
 Post subject: Re: SF-TOGGLE question
PostPosted: Mon Jul 30, 2012 2:52 am  (#4) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
That's a bit puzzling because I can only get this new code to go wrong if I run it without an image open:
PD grayscale Warning
Error while executing image-convert-greyscale-pd:

Error: Procedure execution of gimp-image-convert-grayscale failed on invalid input arguments: Procedure 'gimp-image-convert-grayscale' has been called with an invalid ID for argument 'image'. Most likely a plug-in is trying to work on an image that doesn't exist any longer.

Which is possible because the "Script-Fu>>Refresh Scripts" doesn't honour the "RGB* GRAY*" filter and enables the scripts for all image types (including no image "" )

Kevin


Top
 Post subject: Re: SF-TOGGLE question
PostPosted: Mon Jul 30, 2012 3:11 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
Sorry about that. Mistake on my side.

Thank you for taking the time to help out! I appreciate the helping hand.


Top
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group