Python PIL 绘制圆角矩形

模块:

from PIL import Image
from PIL import ImageDraw
def drawRoundRec(imgPath, color, x, y, w, h, r):
    im = Image.open(imgPath)
    drawObject = ImageDraw.Draw(im)
    
    '''Rounds'''    
    drawObject.ellipse((x,y,x+r,y+r),fill=color)    
    drawObject.ellipse((x+w-r,y,x+w,y+r),fill=color)    
    drawObject.ellipse((x,y+h-r,x+r,y+h),fill=color)    
    drawObject.ellipse((x+w-r,y+h-r,x+w,y+h),fill=color)
    
    '''rec.s'''    
    drawObject.rectangle((x+r/2,y, x+w-(r/2), y+h),fill=color)    
    drawObject.rectangle((x,y+r/2, x+w, y+h-(r/2)),fill=color)
    
    '''SAVE'''    
    im.save(imgPath)

imgPath图片路径
color颜色
x横坐标位置
y纵坐标位置
w width
h height
r 圆角半径

猜你喜欢

转载自blog.csdn.net/qq_22792869/article/details/88643107