Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Auto fit brush to image?
#7
I've got a barebones bit of python code - it sets the brush size and works out the centre coords.

I'v highlighted in red where I'm stuck.
Aspect ratio: not sure what the maths is here

Drawing/stroking: not sure what are valid parameters, correct syntax etc.


Menu location: similarly, not sure of correct menu placement code.

from gimpfu import *

def add_scaled_brush(img, layer):
    # Set up an undo group, so the operation will be undone in one step.
    pdb.gimp_undo_push_group_start(img)

    # Do stuff here.
    xCentre = img.width/2
    yCentre = img.height/2

    brushSize = float(img.width)
    pdb.gimp_context_set_brush_size(brushSize)
    
    aspectRatio = 0.0 #TO DO - calculate based on image height
    pdb.gimp_context_set_brush_aspect_ratio(aspectRatio)
    
    newLayer = pdb.gimp_layer_new(img, img.width, img.height, RGBA_IMAGE, "Scaled Brush", 100.0, LAYER_MODE_NORMAL)
    pdb.gimp_image_insert_layer(img, newLayer, None, 0)
    
    #draw with the current brush
    #something to do with pdb.gimp_paintbrush
    
    # Close the undo group.
    pdb.gimp_undo_push_group_end(img)

register(
    "add_scaled_brush", #Name
    "Add Scaled Brush to Image", #Blurb
    "Scale current brush to image, paint once to new layer.", #help
    "R Soul", #Author
    "CC Licence", #Copyright
    "2024", #Date
    "<Image>/Image/Add Scaled Brush", #Menu path, needs to go somewhere else
    "",      # image types
    [ # No Gui Params
    ],
    [], # Results
    add_scaled_brush) #function

main()
Reply


Messages In This Thread
Auto fit brush to image? - by R Soul - 01-14-2024, 01:21 PM
RE: Auto fit brush to image? - by Ofnuts - 01-14-2024, 02:10 PM
RE: Auto fit brush to image? - by R Soul - 01-14-2024, 05:22 PM
RE: Auto fit brush to image? - by Ofnuts - 01-14-2024, 05:51 PM
RE: Auto fit brush to image? - by R Soul - 01-14-2024, 07:24 PM
RE: Auto fit brush to image? - by Ofnuts - 01-14-2024, 09:41 PM
RE: Auto fit brush to image? - by R Soul - 01-14-2024, 10:02 PM
RE: Auto fit brush to image? - by Ofnuts - 01-14-2024, 10:22 PM
RE: Auto fit brush to image? - by R Soul - 01-15-2024, 09:16 PM

Forum Jump: