python PIL 操作图片

第 0000 题:将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于图中效果

头像

https://github.com/Yixiaohan/show-me-the-code


首先要安装PIL 库,参考http://liam0205.me/2015/04/22/pil-tutorial-basic-usage/

sudo pip install Pillow


然后python 如下

from PIL import Image, ImageDraw
import sys

def DrawNotify(pic,text):
    image = Image.open(pic)
    imgdraw = ImageDraw.Draw(image)
    #should be size ,not size()
    width,height = image.size 
    #notice that --> w
    #           |
    #           V
    #           h
    #should []
    imgdraw.text([0.9*width,0.1*height],text,255) 
    del imgdraw
    #image.show()
    image.save(pic)
    
if __name__ == '__main__':
    #accept first and second arguments 
    DrawNotify(sys.argv[1],sys.argv[2])



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章