It is currently Thu Jun 20, 2013 8:29 am


Latest GIMP Scripts & Plug-ins

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Script-Fu; radial gradient fill
PostPosted: Thu Jul 19, 2012 2:39 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
I have an alpha mask layer which I want to add several radial gradient fills. The problem is that I want it to work with an open image, so I can't use specific x1 y1 x2 y2 coordinates (images will vary in size). I'm thinking I need to use percentages. Is this possible? Am I going down the wrong road?

Any input is greatly appreciated.

Thanks.


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Profile  
 

 Post subject: Re: Script-Fu; radial gradient fill
PostPosted: Thu Jul 19, 2012 3:36 am  (#2) 
Offline
GimpChat Member

Joined: Jun 22, 2012
Posts: 107
I think your approach is right, you'll have to use ratios. Do yourself a sketch of where you want the gradient fills to be, the lengths of the height and width of the image on your sketch will be 1. The x1 y1 y1 y2 of each fill on your sketch will be some ratio of 1, say x1=0,y1=0 to x2=0.5,y2=0.5 for a gradient fill in the lower left quadrant of the image.

In your code read the height and width of the image* that has been loaded then multiply these by the ratios you've worked out for each gradient fill to give you the x1 y1 x2 y2 coordinates you need.

*Check out gimp-image-width and gimp-image-height in the PDB.


Top
 Profile  
 
 Post subject: Re: Script-Fu; radial gradient fill
PostPosted: Thu Jul 19, 2012 3:31 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
*Edit - removed obvious errors

Sorry, I'm not even qualified to be a white belt in Script-Fu. Just started using Script-Fu last week. I've never coded before now.

I think I've figured out the basics, but couldn't find in the forums or in other peoples scripts how to code the specific area I want to gradient file.

So, remembering I'm a newbie (I'll even take the hit noob, because I desperately want to learn Script-Fu), this is all I've been able to put together. The following isn't meant to be perfectly structured, because I don't know the structure:
(define *
(let*
(
(set! x (car (gimp-image-width image)))
(set! y (car (gimp-image-height image)))
(x1)
(x2)
(y1)
(y2)
;(leaving out irrelevant definitions)

)

;leaving out all irrelevant procedures

;Some gradient procedures which I'm really not certain about or how to properly order them (hope I used the word "procedures" correctly).

; now the math
;i.e. x1 = .5x * w
;or as I understand it:

;Starting position

(set! x1 (car (* 0.5 x)))
(set! y1 (car (* 0.5 h)))

;I'm fairly certain this will place my starting position in the center of the image?

;Ending position

(set! x2 (car (* 0.05 x)))
(set! y2 (car (* 0.5 y)))

;I'm fairly certain this will place my ending position to the far left of the starting position ;close to the edge of the image.

)

)

Again, I have now idea how to code this and additionally I want to do several of these gradient files in a single mask layer.

Am I asking for to much help in the coding area. I'm not here to have someone code my work for me. All responses people are giving me, I'm truly using as a learning experience.

With that said, any input is gratefully appreciated.

Thank you.


Last edited by Phoenix999 on Fri Jul 20, 2012 1:39 am, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: Script-Fu; radial gradient fill
PostPosted: Thu Jul 19, 2012 4:29 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Apr 23, 2010
Posts: 842
Location: not from Guildford after all
You have the right idea, though there are some errors in your code examples. The following code will perform a radial gradient from the center of the image to the lower-right corner.

(let* ((layer (car (gimp-image-get-active-layer image)))
       (image-width (car (gimp-image-width image)))
       (image-height (car (gimp-image-height image)))
       (center-x (/ image-width 2))
       (center-y (* image-height 0.5)) ; either is OK
       )
  (gimp-blend layer
              FG-BG-RGB-MODE
              NORMAL-MODE
              GRADIENT-RADIAL
              100 ; Opacity
              0 ; Offset
              0 ; REPEAT-NONE
              FALSE ; Reverse
              TRUE ; supersampling
              3 ; recursion level for supersampling
              0.2 ; supersampling threshold
              TRUE
              center-x ; start at center
              center-y
              image-width ; end on bottom-right corner
              image-height )
  )

_________________
There are two types of people in the world. Those who believe in the principle of bivalence, and those who do not.


Top
 Profile  
 
 Post subject: Re: Script-Fu; radial gradient fill
PostPosted: Fri Jul 20, 2012 3:34 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jul 14, 2012
Posts: 20
Thanks a lot saulgoode! :bigthup

Works perfectly! Just needed to change FG-BG-RGB-MODE to FG-TRANSPARENT-MODE for multiple fills on one mask.

Just as a side note, I kept working on my original thoughts and it works (with help from your script), however your method is far more efficient in every way. I'll just post my script as reference.

(let*

(

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

(x1)
(x2)
(y1)
(y2)
)

(set! x1 (* 0.5 width))
(set! y1 (* 0.5 height))
(set! x2 (* 0.05 width))
(set! y2 (* 0.5 height))

(gimp-edit-blend alphaMask FG-TRANSPARENT-MODE NORMAL-MODE GRADIENT-RADIAL 100 0 REPEAT-NONE FALSE TRUE 3 0.2 TRUE x1 y1 x2 y2)

)

Thanks again!

Tag: x y coordinates multiple several radial gradient fill open image percent percentage percentages


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

* Login  

* Subscribe to Gimp Chat's RSS Feed    * Subscribe to Gimp Chat's Tutorial RSS Feed


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group