from PIL import Image, ImageDraw, ImageFont
其中image是用来读取图像、imagedraw用来绘图,imagefont是用来调用字体。
path=r'stt.jpg'
image = Image.open(path)
image.show()
draw = ImageDraw.Draw(image)
绘制方框rectangle
draw.rectangle([250,250,500,500])
draw.rectangle([500,500,750,750,],fill=250)
draw.rectangle([250,250,750,750],width=20)
image.show()
画线
draw.line([(250,250,),(500,500),(500,750)],fill=255,width=20)
draw.line([250,500,750,1000,1250,250],fill=0,width=10)
添加标签
font=ImageFont.truetype('../model_data/simhei.ttf',90)
draw.text((100,350),'点击关注',fill=(255,0,0),font=font)
draw.text((250,500),'宇宙之靓仔',font=font)
draw.text((500,750),'少妇收割机',fill=(255,0,0),font=font)
image.show()
椭圆、圆形
draw.ellipse((250,250,500,500),fill=250)
绘制圆形
draw.ellipse(((left+right)/2-5,(top+bottom)/2-5,(left+right)/2+5,(top+bottom)/2+5),fill=250)
参考文献:https://blog.csdn.net/m0_56654441/article/details/120663586