It is currently 06 Jul 2020, 11:16

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | 🡆 Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Python rounded rectangle bucket fill problem

GIMP or GIMP LEARN forum related Questions
vndep
Forum Member

Python rounded rectangle bucket fill problem

Post#1 by vndep » 25 Jun 2019, 20:07


In Python, I am trying to add to my background image a rounded rectangle and then fill it with green color. My latest attempt is below, which fails on the following line:

pdb.gimp_image_select_round_rectangle(imageobj, 0, Sign1Xoff, Sign1Yoff, Layer1Width, Layer1Height, cornerradius)

Any help / suggestions / recommendations would be appreciated. Thanks in advance!

Code: Select all

buffer = 10
cornerradius = 15
Layer1Width = 1500
Layer1Height = 500
Sign1Xoff = 100
Sign1Yoff = 100
SignLayer1 = pdb.gimp_layer_new(imageobj, Layer1Width, Layer1Height, 0, 'SignLayer', 100, 0)
imageobj.add_layer(SignLayer1, 1)
pdb.gimp_layer_set_offsets(SignLayer1, Sign1Xoff, Sign1Yoff)
pdb.gimp_context_set_foreground(GreenColor)
# THE CODE FAILS ON THE NEXT LINE
pdb.gimp_image_select_round_rectangle(imageobj, 0, Sign1Xoff, Sign1Yoff, Layer1Width, Layer1Height, cornerradius)
pdb.gimp_edit_bucket_fill(SignLayer1, 0, 0)
GIMP Learn rocks...
0

tim
GL Blogger

Post#2 by tim » 25 Jun 2019, 20:53


what's the error? Can't tell for sure without an error message.

You might be selecting outside of boundary since Layer1Width + Sign1Xoff is outside of area.
width and height paramater passed into round_rectangle should be the width and height of the area that you want to select (not bottom right corner)

UPDATE: Nope, looks like you're passing just corner radius when it's expecting a corner-radius-x and corner-radius-y (2 parameters) instead of one.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0

vndep
Forum Member

Post#3 by vndep » 26 Jun 2019, 16:02


Thanks. That worked well - I apologize for missing that parameter!

Once I have the rounded rectangle, what's the best way to fill it with a color?

I tried gimp_edit_fill and gimp_edit_bucket_fill, both without success

The basic design of the code is: (a) create a layer, (b) make it transparent, (c) add a rounded rectangle onto the layer, (d) fill the rounded rectangle (do NOT fill the layer).

I need to use a layer because I want to delete the rounded rectangle later on - It doesn't seem that the rounded rectangle can be deleted, but a layer on which the rounded rectangle is superimposed can be deleted.

Code: Select all

SignLayer1 = pdb.gimp_layer_new(imageobj, 1500, 500, 0, 'SignLayer', 100, 0)
imageobj.add_layer(SignLayer1, 1)
pdb.gimp_layer_add_alpha(SignLayer1)
pdb.gimp_image_select_contiguous_color(imageobj, 0, SignLayer1, 750, 250)
pdb.gimp_drawable_edit_clear(SignLayer1)
pdb.gimp_image_select_round_rectangle(imageobj, 0, 10, 10, 1500, 500, 20, 20)
pdb.gimp_context_set_foreground(GreenColor)
# RECTANGLE FILL COMMAND HERE		
GIMP Learn rocks...
0

tim
GL Blogger

Post#4 by tim » 26 Jun 2019, 16:13


If you want to select just the round_rectangle use CHANNEL_OP_REPLACE instead of 0. This will make a new selection of just the rounded rectangle.
Then use pdb.gimp_edit_fill(SignLayer1,FILL_FOREGROUND).
Looking at your code looks like you're selecting the whole layer using select contiguous_color then you're adding to that selection (0 flag CHANNEL_OP_ADD) is the rounded rectangle which has no effect since it's already select...so edit fill would probably fill your whole layer and not the rounded rectangle.
aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
0


GIMP/GL:  Tutorials | Tips | 🡆 Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 6 guests