码迷,mamicode.com
首页 > 编程语言 > 详细

python PIL 操作图片

时间:2016-03-16 01:22:17      阅读:209      评论:0      收藏:0      [点我收藏+]

标签: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])



本文出自 “ryanscn” 博客,请务必保留此出处http://ryanscn.blog.51cto.com/2725212/1751550

python PIL 操作图片

标签:python   pil   

原文地址:http://ryanscn.blog.51cto.com/2725212/1751550

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!