You are here

Gimp versus Script-Fu Selection Borders

Hey all,

I am new to these forums and have a question or two.

  • Gimp Version: GIMP 2.6.6
  • OS: Windows XP

I am writing a script and one of the things i need to do is select the alpha of active layer, then put a 5px border with a feather on it. The GUI under Select/>Border seems to have the option of add feather to border, while the Script-Fu gimp-selection-border does not. I am doing all of my testing using the Script-Fu console and have noticed that the two have very different outcomes.

Procedure 1:

  • Create New Image 128px x 128px
  • Select All


  • Select->Border->20 (px)
  • Outcome: Border of 10px shown since 10px outside are cut off


  • Console: (gimp-selection-border 1 20)
  • Outcome: Selection is gone

Procedure 2:

  • Create New Image 128px x 128px
  • Select Rectangle in Center 60px x60px


  • Select->Border->10(px)
  • Outcome: Border shown 10px radius


  • Console: (gimp-selection-border 1 10)
  • Outcome: Border shown 10px outer only

So what I have noticed is that these two methods don't coincide. Gimp-selection-border creates a border around the selection whereas through the GUI (Select->Border) a border is created with a radius outside and a radius inside.

How can I script the functionality of the GUI version since that is what I would like to use?


While the two are different I don't see the same behaviour as you.

If I do a select->border 20 I get a 40px selection (20 inside and 20 outside the original selection). I assume you have feather checked, which creates a selection 20 inside and 20 outside BUT displays the selection martching ants at the 10px mark (50% selected).

Without feathering I get the exact same results with the (gimp-selection-border) call EXCEPT for when there is "all" selected, in which case nothing is selected after the PDB call.

To get what you want (I think) try the following:

Save the selection to a channel (A)
Selection shrink by X pixels with gimp-selection-shrink and save it to channel (B)
Reload saved channel A
Selection grow by X pixels with gimp-selection-grow.
Subtract the saved channel (B) using gimp-selection-combine and the mode CHANNEL-OP-SUBTRACT
Gaussian Blur the selection by the feather amount desired. Get the selection channel with (car (gimp-image-get-selection img))

-Rob A>

Hey Rob, Thanks for the response. I figured what I was doing wrong with the selection size, the gimp-selection-border needs the total pixel size. So 20px from the GUI would be 40px for the script. On the other hand following your response I do not get similar results when trying to mimic the add border with feather from the GUI.

For the GUI I used Add border 20px with feather option. Filled with white.

For Script-fu:

4 is the image number for me... just replace with own image number.

(let* ((channela 0) (channelb 0)) (set! channela (car (gimp-selection-save 4))) (gimp-selection-shrink 4 10) (set! channelb (car (gimp-selection-save 4))) (gimp-selection-load channela) (gimp-selection-grow 4 10) (gimp-selection-combine channelb 1) (gimp-selection-feather 4 20) (gimp-edit-fill 8 1) )

Here are my results:

I would like to mimic those sharp edges as in the GUI's version.


Sorry -

A Gaussian blur won't be able to get that /\ shape as (by definition) it follows a gaussian curve.

You might have better luck using the wrapmap python plugin:

The other way is to do the math and iterate it yourself by gimp-selection-border to 1 px radius, filling that, then growing it iteratively gimp-selection-grow

Look at the chisel script I wrote: it does something quite similar to make the bumpmaps.

-Rob A>

The gimp-selection-border operation always results in feathering. The PDB function is effectively missing the option NOT to feather. When this option (to not feather the result) was added to the GUI dialog (, it was not necessary to modify the PDB interface since scripts and plug-ins can achieve the same result by "sharpening" the feathered selection with a threshold of "0".

(gimp-selection-border image radius)
(gimp-threshold (car (gimp-image-get-selection image)) 0 0)
(gimp-selection-invert image)

This is exactly what I was looking for. To think i didn't actually fill in the gimp-selection-border to see the feathering, I just incorrectly assumed since it didn't mention it anywhere. Also the script to create the no feather works great too. Thanks saulgoode and Rob for your help. :)

Subscribe to Comments for "Gimp versus Script-Fu Selection Borders"