zoukankan      html  css  js  c++  java
  • python pillow

    https://www.cnblogs.com/morethink/p/8419151.html#%E7%9B%B4%E6%8E%A5%E6%8F%92%E5%85%A5%E6%8E%92%E5%BA%8F

    https://www.cnblogs.com/brookshi/p/8414881.html

    https://www.cnblogs.com/zhouyubo/p/8412840.html

    https://www.cnblogs.com/cr330326/p/8419899.html

    https://www.cnblogs.com/xybaby/p/8403461.html

    http://www.cnblogs.com/xybaby/p/7954610.html

    http://www.cnblogs.com/xybaby/p/6406191.html

    http://www.cnblogs.com/xybaby/p/6343285.html

    https://www.cnblogs.com/liuyun1995/p/8416340.html

    https://www.cnblogs.com/AdaminXie/p/8379749.html

    https://www.cnblogs.com/JJJ1990/p/8384386.html

    https://www.cnblogs.com/zhenlingcn/p/8386214.html

    http://www.cnblogs.com/zhenlingcn/p/8337788.html

    TutorialDemo001.py

    # coding: utf-8
    
    from PIL import Image
    import os, sys
    
    Int_Len = 5
    
    def getPicInfo(pic):
        im = Image.open(pic)
        print("--------------------")
        print("file name:	" + im.filename)
        print("format:		" + im.format)
        print("size:		" + str(im.size))
        print("mode:		" + im.mode)
        return im
    
    
    def convertFormat(pic, format):
        pathNew = getNewFormatPath(pic, format)
        try:
            im = Image.open(pic)
            im.save(pathNew, format)
            getPicInfo(pathNew)
            return pathNew
        except IOError:
            print("Cannot create new Format %s for %s." % format, pic)
            return None
    
    
    def convertThumbnails(pic, rate=1, format='JPEG'):
        pathNew = getThumbnailsPath(pic, r"thumbnails", format)
        if (pic != pathNew):
            try:
                im = Image.open(pic)
                size = (int(im.size[0] * rate), int(im.size[1] * rate))
                im.thumbnail(size)
                im.save(pathNew, format)
                getPicInfo(pathNew)
                return pathNew
            except IOError:
                print("Cannot create thumbnail for ", pic)
                return None
    
    
    def getNewFormatPath(pic, format):
        pathSegs = os.path.splitext(pic)
        count = 1
        while True:
            pathNew = pathSegs[0] + r"-" + str(count).zfill(Int_Len) + "." + format.lower()
            if os.path.exists(pathNew):
                count += 1
                pathNew = pathSegs[0] + r"-" + str(count).zfill(Int_Len) + "." + format.lower()
            else:
                return pathNew
    
    
    def getThumbnailsPath(pic, suffix, format):
        pathSegs = os.path.splitext(pic)
        count = 1
        while True:
            pathNew = pathSegs[0] + r"-" + str(count).zfill(Int_Len) + r"-" + suffix + "." + format.lower()
            if os.path.exists(pathNew):
                count += 1
                pathNew = pathSegs[0] + r"-" + str(count).zfill(Int_Len) + r"-" + suffix + "." + format.lower()
            else:
                return pathNew
    
    
    if __name__ == "__main__":
        pic1 = r"res/MIT-001.jpg"
        pic2 = r"res/MIT-002.jpg"
    
        # im = getPicInfo(pic1)
        # r,g,b = im.split()
        # r.rotate(45).show()
        # g.resize((100,200)).show()
        # b.show()
        # im.convert("L").convert("RGB").show()
    
        # convertThumbnails(pic1, 0.5)
    
        path = convertFormat(pic1, 'PNG')
        print(os.path.abspath(path))
    

      

  • 相关阅读:
    js原型对象与Java类的比较
    javascript特效--制作背景电子钟(整点时祝贺生日快乐)
    Java web MVC开发模式入门感悟
    重新审视面向对象编程
    10-排序4 统计工龄(20 分)
    基数排序
    表排序
    快速排序
    09-排序3 Insertion or Heap Sort(25 分)
    09-排序2 Insert or Merge(25 分)
  • 原文地址:https://www.cnblogs.com/coder211/p/8386352.html
Copyright © 2011-2022 走看看