zoukankan      html  css  js  c++  java
  • python之~利用PIL模块在图片上写写画画

    借鉴了教程:

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

    完成作业如下:

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

    from PIL import Image,ImageDraw,ImageFont
    
    FileName = 'E:savepictureyuantu.jpg'
    OutName = 'E:savepictureshuiyin.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)

    原图

    效果图

    哈哈好喜欢樱桃小丸子。

  • 相关阅读:
    js固定在顶部
    css垂直居中
    HTML 5离线存储
    jdbc数据库操作
    I/O输入输出流
    异常处理
    java实现冒泡排序算法
    Java 方法
    java 循环 基本类型
    Java中Arrays工具类
  • 原文地址:https://www.cnblogs.com/pheobe/p/5776336.html
Copyright © 2011-2022 走看看