lb_Mvp的个人空间 https://blog.eetop.cn/1185438 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

Python PIL 实现图片上加数字

已有 2748 次阅读| 2015-11-7 19:31 |个人分类:python学习

1.   Python PIL 库的下载和安装

Python PIL 的官方下载地址 http://effbot.org/downloads#pil ,只更新到Python2.7
我下载的是Python3.4,所以没去下载官方的库文件(不知道是不是真的不能用,没试)

http://www.lfd.uci.edu/~gohlke/pythonlibs/
上面这个网址提供了大多数的python第三方库,找到pillow,a replacement for PIL
下载 Pillow-3.0.0-cp34-none-win32.whl ,cp34对应我python的版本3.4,win32对应我python的版本是32位的
然后用pip 在windows命令行下安装
pip install Pillow-3.0.0-cp34-none-win32.whl

2. python PIL 库的用法可以在官方文档中学习
http://effbot.org/imagingbook/

3. 程序示例
目标:将你的 QQ 头像(或者微博头像)右上角加上红色的数字

from PIL import Image, ImageDraw, ImageFont

def add_num(img):
    draw = ImageDraw.Draw(img)
    # use a truetype font
    myfont = ImageFont.truetype('C:/windows/fonts/Arial.ttf', size=40)
    fillcolor = "#ff0000"     #R,G,B的值
    width,height = img.size
    draw.text((width-50, 0), '99', font=myfont, fill=fillcolor)
    img.save('result.jpg','jpeg')

    return 0

if __name__ == '__main__':
    image = Image.open(r'F:\pic.jpg')
    add_num(image)

点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 3

    获赞
  • 2

    评论
  • 753

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-3 03:32 , Processed in 0.022435 second(s), 14 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部