Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
from PIL import Image, ImageDraw
def round_corner(radius, fill):
"""Draw a round corner"""
corner = Image.new('RGBA', (radius, radius), (0, 0, 0, 0))
draw = ImageDraw.Draw(corner)
draw.pieslice((0, 0, radius * 2, radius * 2), 180, 270, fill=fill)
return corner
def procent_line(size, radius, fill1, fill2, p):
"""Draw a rounded rectangle"""
width, height = size
rectangle = Image.new('RGBA', size, fill2)
corner_b = round_corner(radius, fill2)
corner_f = round_corner(radius, fill1)
rectangle.paste(corner_f, (0, 0))
rectangle.paste(corner_f.rotate(90), (0, height - radius)) # Rotate the corner and paste it
rectangle.paste(corner_b.rotate(180), (width - radius, height - radius))
rectangle.paste(corner_b.rotate(270), (width - radius, 0))
rectangle.paste(corner_f.rotate(180), (int(width*p - radius), height - radius),corner_f.rotate(180))
rectangle.paste(corner_f.rotate(270), (int(width*p - radius), 0),corner_f.rotate(270))
ImageDraw.Draw(rectangle).rectangle([radius,0,int(width*p - radius),height],fill=fill1)
return rectangle
img = procent_line((400, 40), 20, "yellow", "gray", .25)
img.show()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question