python之~利用PIL模块在图片上写写画画

 

借鉴了教程:

http://yxnt.github.io/2016/05/15/Pillow-Python3.5/

 

完成作业如下:

 

 

后来学着写给自己的图片加了水印。

from PIL import Image,ImageDraw,ImageFont

FileName = 'E:\savepicture\yuantu.jpg'
OutName = 'E:\savepicture\shuiyin.jpg'

BlogName = '小旋子的代码自习室'
BlogSite = 'http://www.cnblogs.com/pheobe/'

def Add_shuiyin(FileName,OutName):
    with Image.open(FileName).convert('RGBA') as im:
        shuiyin = Image.new(im.mode,im.size)
        d = ImageDraw.Draw(shuiyin)
        Font1 =ImageFont.truetype( 'simfang.ttf',size=30)
        Font2 =ImageFont.truetype( 'simfang.ttf',size=20)
        d.text((100,300),BlogName,fill=(0,0,0),font=Font1)
        d.text((90,330),BlogSite,fill=(0,0,0),font=Font2)

        out = Image.alpha_composite(im,shuiyin)

        out.save(OutName)

        out.show()

Add_shuiyin(FileName,OutName)

 

原图

效果图

 

哈哈好喜欢樱桃小丸子。

posted on 2016-08-16 14:41  Pheobeee  阅读(3638)  评论(1编辑  收藏  举报