Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to draw a triangle with PIL?

i am trying to draw a triangle with PIL ImageDraw this is the code that i have

    t1 = int(tri[0])
    t2 = int(tri[1])
    t3 = int(tri[2])
    t4 = int(tri[3])
    t5 = int(tri[4])
    t6 = int(tri[5])
    t7 = int(tri[6])
    t8 = int(tri[7])
    t9 = int(tri[8])
    t10 = int(tri[9])
    draw.polygon((t1,t2),(t3,t4),(t5,t6), fill=(t7,t8,t9,t10))

i am getting the error

TypeError: polygon() got multiple values for argument 'fill'

is there any way that i can make a triangle without getting this error

python 2.7

like image 415
gokul gupta Avatar asked Sep 03 '25 15:09

gokul gupta


1 Answers

Like this:

from PIL import Image,ImageDraw

# Create empty black canvas
im = Image.new('RGB', (255, 255))

# Draw red and yellow triangles on it and save
draw = ImageDraw.Draw(im)
draw.polygon([(20,10), (200, 200), (100,20)], fill = (255,0,0))
draw.polygon([(200,10), (200, 200), (150,50)], fill = 'yellow')

im.save('result.png')

enter image description here

like image 129
Mark Setchell Avatar answered Sep 05 '25 15:09

Mark Setchell