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)

 

原圖

效果圖

 

哈哈好喜歡櫻桃小丸子。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM