pythondrawingjythonshapesjes

Drawing a narrow filled arc in python


I am trying to draw a narrow filled arc in python--the height is small and the width is very wide. I want it to startX at 250, startY at 550, i want the width to be 245, the height to be 15... and then I am stuck.

I have tried a few different things for the start/angle but it doesn't look right: 0/90.

I just want it to be a straight horizontal line with a small arc attached to make a semi-circle.

Here is an example of what I tried:

             addArcFilled(pic, 250, 550,245,15, 0, 90, blue)

Solution

  • @knells Probably this functions does exactly what you need: http://pillow.readthedocs.io/en/3.1.x/reference/ImageDraw.html#PIL.ImageDraw.PIL.ImageDraw.Draw.arc

    IL.ImageDraw.Draw.arc(xy, start, end, fill=None) Draws an arc (a portion of a circle outline) between the start and end angles, inside the given bounding box.

    PIL.ImageDraw.Draw.chord(xy, start, end, fill=None, outline=None) Same as arc(), but connects the end points with a straight line.

    Sample code below:

    from PIL import Image, ImageDraw
    # get an image
    im = Image.open('test.png').convert('RGBA')
    
    # create draw context and draw arc
    draw = ImageDraw.Draw(im)
    draw.chord([10,10, 200, 200], 0,45, fill=0)
    del draw
    
    im.save('test_out.png', "PNG")
    
    im.show()