记录Python图像处理Pillow-插入文本或图形水印方法,首先下载一个中文字体,名字改为英文名字即可。
附上代码:
# _*_ coding:utf-8 _*_
__author__ = 'admin'
from PIL import Image, ImageDraw, ImageFont
im = Image.open(r"linuxidc.com.jpg")
draw = ImageDraw.Draw(im)
myfont = ImageFont.truetype(u"linuxidc.ttf", size=35)
fillcolor = 'red'
draw.text((300, 90), u"Linux公社的文字水印www.linuxidc.com", font=myfont, fill=fillcolor)
im.save(r"www.linuxidc.jpg", 'JPEG')
原图:
效果图:
下面来看下插入图形,借鉴于其他社友的材料,这里也是写下“红点提醒”吧
上代码:
# _*_ coding:utf-8 _*_
__author__ = 'admin'
from PIL import Image, ImageDraw, ImageFont
im = Image.open(r"linuxidc.com.png")
draw = ImageDraw.Draw(im)
myfont = ImageFont.truetype('linuxidc.ttf', 60)
width, height = im.size
# 画圆形
draw.ellipse((200,200, 550, 550), fill='red', outline='red')
# 插入文本
draw.text((260, 330), 'Linux公社', font=myfont, fill='white')
im.show()
效果图:
(这样你就可以自己制作类似的趣味头像了,反正我是意识到了,语言间各有各的好处,只有你能否将它学以致用,发挥好)
(向一切因为爱好而学习程序的人致敬!)
更多Python相关信息见Python 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=17
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx
本文永久更新链接地址:https://www.linuxidc.com/Linux/2020-01/162140.htm
