zoukankan      html  css  js  c++  java
  • Python之Python Imaging Library

    document:http://effbot.org/imagingbook/pil-index.htm http://pillow.readthedocs.io/en/3.1.x/index.html

    from PIL import Image

    1.打开图片

    img = Image.open(fileName)

    2.保存图片

    img.save(imgName)

    3.调整图片大小

    def resize(self, width, height):
        o_width, o_height = img.size
        o_ratio = o_width/float(o_height)
        n_ratio = width/float(height)

        if o_ratio > n_ratio:
            re_ration = width/float(o_width)
            a_height = int(re_ration*o_height)
            img = self.img.resize((width,a_height),Image.ANTIALIAS)
        else:
            re_ration = height/float(o_height)
            a_width = int(re_ration*o_width)
            img = img.resize( (a_width,height),Image.ANTIALIAS)

        img.save('test.jpg')

    4.新建图片

    img = Image.new("RGB", (width, height), "black")

    5.粘贴拷

    box = (100,100,500,500)#设置要拷贝的区域  

    region = im.crop(box)  

    region = region.transpose(Image.ROTATE_180)#从字面上就可以看出,先把region中的Image反转180度,然后再放回到region中。  

    im.paste(region, box)#粘贴box大小的region到原先的图片对象中。  


      

  • 相关阅读:
    性能分析之路-------各指标代表意思以及分析
    selenium python 定位一组对象
    python 操作word文档
    nmon的安装以及使用
    nginx的监控配置
    selenium 一个简单的流程
    Fiddler手机抓包设置
    urllib、urllib2、urllib3区别和使用
    mysql数据库改名的方法
    Python之pymysql
  • 原文地址:https://www.cnblogs.com/huangshiyu13/p/5955724.html
Copyright © 2011-2022 走看看