Re: Optimizing border-like selection in python

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The code should work for any shape of selection (for instance after a 
text-to-selection). Actually the plugin this routine is part of hasn't 
got much merit on rectangular/circular selections...


On 25/09/2010 00:27, Jerry Baker wrote:
>
> Ahh... autoformatting... this should be easier to read... (sorry)
>
> def create_border(image, selection_type='rectangle', size=1):
> is_selection, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)
>
> if is_selection:
> if size < 1:
> size = 1
> if selection_type =='rectangle':
> pdb.gimp_rect_select(image,
> x1+size,
> y1+size,
> (x2-x1)-(size*2),
> (y2-y1)-(size*2),
> CHANNEL_OP_SUBTRACT,
> False,
> 0)
> elif selection_type == 'ellipse':
> pdb.gimp_ellipse_select(image,
> x1+size,
> y1+size,
> (x2-x1)-(size*2),
> (y2-y1)-(size*2),
> CHANNEL_OP_SUBTRACT,
> True,
> False,
> 0)
> else:
> gimp.message("Please make a selection...")
>
> def test_plugin(image, drawable):
> image.undo_group_start()
>
> # A rectangular selecion with default settings...
> create_border(image)
>
> # Ellipse with custom settings... Uncomment to activate
> #create_border(image, selection_type='ellipse', size=3)
>
> # Fill
> pdb.gimp_edit_fill(drawable, 0)
> pdb.gimp_selection_none(image)
>
> image.undo_group_end()
>
> On 09/24/2010 06:18 PM, Jerry Baker wrote:
>> Calculating a new selection from the current selection would be faster
>> (I think):
>>
>> def create_border(image, selection_type='rectangle', size=1):
>> is_selection, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)
>>
>> if is_selection:
>> if size< 1:
>> size = 1
>> if selection_type =='rectangle':
>> pdb.gimp_rect_select(image, x1+size, y1+size,
>> (x2-x1)-(size*2), (y2-y1)-(size*2), CHANNEL_OP_SUBTRACT, False, 0)
>> elif selection_type == 'ellipse':
>> pdb.gimp_ellipse_select(image, x1+size, y1+size,
>> (x2-x1)-(size*2), (y2-y1)-(size*2), CHANNEL_OP_SUBTRACT, True, False, 0)
>> else:
>> gimp.message("Please make a selection...")
>>
>> def test_plugin(image, drawable):
>> image.undo_group_start()
>>
>> create_border(image) # A rectangular selecion with default
>> settings...
>> #create_border(image, selection_type='ellipse', size=3) # Or
>> Ellipse with custom settings...
>>
>> # Fill
>> pdb.gimp_edit_fill(drawable, 0)
>> pdb.gimp_selection_none(image)
>>
>> image.undo_group_end()

_______________________________________________
Gimp-developer mailing list
Gimp-developer@xxxxxxxxxxxxxxxxxxxxxx
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux