How can I automate some simple steps within the GIMP?

4

I'm trying to use GIMP to automate 3 actions upon a user defined selection in the currently active image -

  • Grow selection by 2
  • Add border to selection (width of 2, with feathered edges)
  • Fill the whole selection with colour #FF0000 (red)

I've discovered the Script-Fu Console, and have browsed fo the (gimp-selection-grow image steps) command, but I'm now kind of stuck.

Under paramaters, the documentation simply says

image IMAGE The image
steps STEPS Steps of grow (in pixels) (steps >= 0)

Now steps is pretty obvioius, but I'm stuck on image. Surely with the action being carried out on a selection, the grow should be appled to the active selection?

I tried leaving image as is, in the hopes that GIMP would realise I wanted to action the grow on the active selection, but I received the error Error: ( : 1) eval: unbound variable: image

Can anyone please help to get me started?

EDIT

I've now discovered a tutorial for adding scripts to the GIMP using Python (http://www.exp-media.com/content/extending-gimp-python-python-fu-plugins-part-2), and I have my script registered and, to some extent, working.

Pleae see my answer below.

However, one problem does remain - I'd like to make it so that my menu entry is greyed out until a selection is made, as opposed to always visible.

David Gard

Posted 2014-10-21T13:33:43.000

Reputation: 1 368

Answers

1

With the assistence of this tutorial, I have now been able to create the plugin almost exactly as I would like it.

#**
 # Import the relevant modules
 #*
from gimpfu import *


#**
 # Preform the main script function
 #*
def add_border_to_selection(image, drawable, grow_by, border_thickness, border_feather) :
    pdb.gimp_selection_grow(image, grow_by)
    pdb.gimp_selection_border(image, border_thickness)
    pdb.gimp_bucket_fill(drawable, 0, 0, 100, 15, TRUE, 0, 0)
    return


#**
 # Register the plugin
 #*
register(
    "djg-border-and-fill",
    "Border and Fill Selection",
    "This script adds first grows your selection, then adds a border, and finally fills the border in red.",
    "David Gard (DJG-Dev)",
    "GPL V2 License",
    "October 2014",
    "<Image>/Select/Border and Fill...",
    "*",
    [
      (PF_SPINNER, 'grow_by', 'Grow selection by (px)...', 2, (0,5,1)), 
      (PF_SPINNER, 'border_thickness', 'Border selection by (px)...', 2, (0,5,1)), 
      (PF_TOGGLE, 'border_feather', 'Feather border edges', TRUE)
    ],
    [],
    add_border_to_selection,
    )

main()

David Gard

Posted 2014-10-21T13:33:43.000

Reputation: 1 368