Python图像处理Pillow-插入文本或图形水印


记录Python图像处理Pillow-插入文本或图形水印方法,首先下载一个中文字体,名字改为英文名字即可。

附上代码:

#   _*_ coding:utf-8 _*_
__author__ = 'admin'

from PIL import Image, ImageDraw, ImageFont
im =  Image.open(r"linuxboy.net.jpg")
draw = ImageDraw.Draw(im)
myfont = ImageFont.truetype(u"linuxidc.ttf", size=35)
fillcolor = 'red'
draw.text((300, 90), u"linuxboy的文字水印www.linuxboy.net", font=myfont, fill=fillcolor)
im.save(r"www.linuxidc.jpg", 'JPEG')

原图:

Python图像处理Pillow-插入文本或图形水印

效果图:

Python图像处理Pillow-插入文本或图形水印

下面来看下插入图形,借鉴于其他社友的材料,这里也是写下“红点提醒”吧

上代码:

#   _*_ coding:utf-8 _*_
__author__ = 'admin'

from PIL import Image, ImageDraw, ImageFont
im =  Image.open(r"linuxboy.net.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), 'linuxboy', font=myfont, fill='white')
im.show()

效果图:

Python图像处理Pillow-插入文本或图形水印

(这样你就可以自己制作类似的趣味头像了,反正我是意识到了,语言间各有各的好处,只有你能否将它学以致用,发挥好)

(向一切因为爱好而学习程序的人致敬!)

https://www.linuxboy.net/topicnews.aspx?tid=17

linuxboy的RSS地址:https://www.linuxboy.net/rssFeed.aspx

本文永久更新链接地址:https://www.linuxboy.net/Linux/2020-01/162140.htm

相关内容

    暂无相关文章