Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Graphics > GIMP (GNU Image Manipulation Program) > Re: making a sc...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 15 of 24 Topic 3079 of 3157
Post > Topic >>

Re: making a script

by Niels Giesen <niels.giesen@[EMAIL PROTECTED] > Sep 26, 2008 at 09:53 AM

houghi <houghi@[EMAIL PROTECTED]
> writes:

> houghi wrote:
>>> To use the "script-fu-fuzzy-border" function in batch
>>> mode you need to first execute the required gimp
>>> functions to load an image by reading one from a file.
>>
>> OK and how do I do that?
>
> OK, I am again loosing several hours over this. I start with
> http://www.gimp.org/tutorials/Basic_Batch/
and that works.
>
> What I see there is absolutely no serious attempt to explain anything.
> It is more a 'How to drive a car? You step in and drive away.' type of
> thing. Pity to see that sch a thing where the GIMP could beat anything
> is so neglected. :-( Anywah ..
>
> I see two places where things are defined. The first is the define of
> simple-unsharp-mask. The second is the plug-in-unsharp-mask.
>
> Let me look at the first thing. There I see respectivaly filename,
> radius, amount and threshold. Those are used as well in the commandline
> with "foo.png" 5.0 0.5 0.
>
> However when I look in Xtns, I see much more parameters. With a lot of
> trial and error I was able to make a sharpen script that worked.
>
> So I then try to re-write it for the fuzzy border and get to the
> following:
> (define (border-fuzz filename
>                 color
>                 value
>                 toggle
>                 value
>                 toggle
>                 value
>                 toggle
>                 toggle
>                 )
> (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename
> filename)))
> (drawable (car (gimp-image-get-active-layer image)))) 
> (script-fu-fuzzy-border RUN-NONINTERACTIVE
>                            image drawable 
> 		color
>                 value
>                 toggle
>                 value
>                 toggle
>                 value
>                 toggle
>                 toggle  
>                 )
> (set! drawable (car (gimp-image-get-active-layer image)))
> (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
> (gimp-image-delete image)))
>
> As command I give the following on one line:
> gimp -i -b '(border-fuzz "foo.png" (0;0;0) 50 0 50 0 0 0 0)' -b
> '(gimp-quit 0)'
>
> It tells me it is successfull and nothing happens. I have no idea where
> I am going wrong as there is no do***entation available. I also doubt
> that I am the only person in the world wjo wants to use gimp in a script
> mode. So please can somebody show me what it must be instead of what I
> have. No explanation, just the raw code. I can then try to fugure out
> myself what I am doing wrong and apply it to other things.
>
> I will then probably even write it all down for others to use.
>
> houghi
> -- 
> The whole principle [of censor****p] is wrong. It's like demanding that 
> grown men live on skim milk because the baby can't have steak.
> 		-- Robert A. Heinlein in "The Man Who Sold the Moon"

Sorry, not giving the raw code, but code interspersed with comments. I
agree that do***entation on script-fu scripting is poor, and
discoverability low. To aid myself in writing script-fu scripts, I
have written a gimp-mode for Emacs, that helps a lot (by completing
arguments and functions, providing easy access from within the code to
the procedural do***entation, having an interactive REPL, etc.). You may
find that of use (if you already use Emacs), though granted, it is not
yet as stable as I would like it to be and I do not guarantee
flawlessness. It is at http://niels.kicks-ass.org/gimpmode/

If you do not want to use that, in the development thereof, I have
searched the web, and found the following resources to be of use:

http://docs.gimp.org/en/gimp-using-script-fu-tutorial.html
http://www.ve3syb.ca/wiki/doku.php?id=software:sf:start
http://mitpress.mit.edu/sicp/full-text/book/book.html
http://tech.groups.yahoo.com/group/script-fu/

Besides that, Akkana Peck's book on the GIMP also has a part on script-fu.


And you can of course always browse the procedural browser inside the
GIMP and have a script-fu console to test your scripts interactively,
though its usability is quite low (hence gimp-mode). And be wary of
the RUN-(NON)INTERACTIVE argument to be left out (gimp-mode simply
strips these arguments from the do***entation so as not to confuse us
poor script-fu coders).

Another way of debugging your scripts is turning tracing on, by issuing 
(tracing TRUE), so, for instance: 

gimp -ic -b "(begin (tracing TRUE) (your code ... ) (gimp-quit
RUN-NONINTERACTIVE))"

and you can turn it off with (tracing FALSE).

;; the code: (comments run from a semicolon to end of line, and are
;; ignored by the scheme reader)

(define (border-fuzz filename
		     color
		     border-size
		     blur-border?
		     granularity
		     add-shadow?
		     shadow-weight
		     ;; As you are saving to the same file again,
		     ;; working on a copy is nonsense, so do not ask
		     ;; for work-on-copy? 
;;work-on-copy?
		     ;; You will always want to flatten your image, as
		     ;; you are performing batch mode, so we will
		     ;; simply pass the value TRUE to
		     ;; script-fu-fuzzy-border for flatten-image argument. (If
		     ;; given value FALSE, you'll end up with a black
		     ;; image).
;;flatten-image?                   
		     )
  (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename
filename)))
	 (drawable (car (gimp-image-get-active-layer image)))) 
    (script-fu-fuzzy-border
     ;; As I said in an earlier post, script-fu calling script-fu
     ;; leaves out first RUN-(NON)INTERACTIVE argument. Commented out
     ;; RUN-NONINTERACTIVE
			    image 
			    drawable 
			    color
			    border-size
			    blur-border?
			    granularity
			    add-shadow?
			    shadow-weight
			    ;; see first comment
			    FALSE
			    ;; see first comment
			    TRUE)
    (set! drawable (car (gimp-image-get-active-layer image)))
    (gimp-file-save RUN-NONINTERACTIVE image drawable filename filename)
    (gimp-image-delete image)))

;; Example of usage: 

(border-fuzz "/home/sharik/Pictures/skrinka.jpg" 
	     ;; this is how we specify a color (a semicolon means the
	     ;; rest of the line is to be seen as a comment, so
	     ;; '(0;0;0) was incorrect) :
	     '(0 0 0) 
	     50 
	     0 
	     ;; (max value for granularity in script-fu-fuzzy-border is 16)
	     16 
	     FALSE 
	     ;; (though minimum value says 0, this results in a
	     ;; division by zero; this looks like a bug in
	     ;; script-fu-fuzzy-border so maybe we should file a re****t.)
	     1 
	     ;; as said in first comment, work-on-copy should always
	     ;; be FALSE, and flatten-image should always be TRUE, so
	     ;; getting rid of these arguments.
	     )

From bash: 
gimp -i -b "(begin (border-fuzz \"foo.png\" '(0 0 0) 50 0 16 FALSE 1
FALSE) (gimp-quit RUN-NONINTERACTIVE))"

Hope this is of use.

Regards,

Niels Giesen.
 




 24 Posts in Topic:
making a script
-=MrX=- <herrie@[EMAIL  2008-09-22 18:41:57 
Re: making a script
houghi <houghi@[EMAIL   2008-09-22 21:21:18 
Re: making a script
houghi <houghi@[EMAIL   2008-09-22 23:24:26 
Re: making a script
-=MrX=- <herrie@[EMAIL  2008-09-23 16:51:10 
Re: making a script
houghi <houghi@[EMAIL   2008-09-23 17:07:05 
Re: making a script
houghi <houghi@[EMAIL   2008-09-23 22:24:15 
Re: making a script
-=MrX=- <herrie@[EMAIL  2008-09-24 16:03:14 
Re: making a script
houghi <houghi@[EMAIL   2008-09-24 16:53:08 
Re: making a script
-=MrX=- <herrie@[EMAIL  2008-09-25 08:21:13 
Re: making a script
houghi <houghi@[EMAIL   2008-09-25 11:20:33 
Re: making a script
Troy Piggins <usenet-0  2008-09-23 08:00:12 
Re: making a script
floyd@[EMAIL PROTECTED]   2008-09-25 04:57:05 
Re: making a script
houghi <houghi@[EMAIL   2008-09-25 16:05:01 
Re: making a script
houghi <houghi@[EMAIL   2008-09-26 01:15:43 
Re: making a script
Niels Giesen <niels.gi  2008-09-26 09:53:44 
Re: making a script
houghi <houghi@[EMAIL   2008-09-26 12:04:58 
Re: making a script
Giacomo Boffi <giacomo  2008-09-26 12:34:41 
Re: making a script
houghi <houghi@[EMAIL   2008-09-26 12:56:37 
Re: making a script
Niels Giesen <niels.gi  2008-09-26 22:03:52 
Re: making a script
houghi <houghi@[EMAIL   2008-09-26 20:38:05 
Re: making a script
floyd@[EMAIL PROTECTED]   2008-09-26 01:21:17 
Re: making a script
houghi <houghi@[EMAIL   2008-09-26 12:51:49 
Re: making a script
houghi <houghi@[EMAIL   2008-09-26 22:13:07 
Re: making a script
Dirk Dietrich <kaufinf  2008-10-03 18:16:16 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Dec 4 18:04:30 CST 2008.