zoukankan      html  css  js  c++  java
  • python 利用PIL库进行更改图片大小的操作

    python 是可以利用PIL库进行更改图片大小的操作的,当然一般情况下是不需要的,但是在一些特殊的利用场合,是需要改变图片的灰度或是大小等的操作的,其实用python更改图片的大小还是蛮简单的,只需要几行代码,有一点可能刚入门的小伙伴们可能不知道PIL库,PIL是一个库的简写,他的真名叫做pillow,因此,需要pip install pillow 用anaconda的话是conda install pillow千万不要pip/conda install PIL咯,下面贴出代码,希望对一些小伙伴们能有帮助

    #encoding=utf-8
    import os
    import os.path
    from PIL import Image
    '''
    filein: 输入图片
    fileout: 输出图片
     输出图片宽度
    height:输出图片高度
    type:输出图片类型(png, gif, jpeg...)
    '''
    def ResizeImage(filein, fileout, width, height, type):
      img = Image.open(filein)
      out = img.resize((width, height),Image.ANTIALIAS) #resize image with high-quality
      out.save(fileout, type)
    if __name__ == "__main__":
      filein = r'image	est.png'
      fileout = r'image	estout.png'
      width = 60
      height = 85
      type = 'png'
      ResizeImage(filein, fileout, width, height, type)
    

      

  • 相关阅读:
    python知识合集
    可拖动的DIV
    JavaScript创建对象
    JavaScript prototype
    CSS media queries
    JavaScript作用域链
    JavaScript包装对象
    贫下中农版jQuery
    JavaScript 命名空间
    z-index 应用简单总结
  • 原文地址:https://www.cnblogs.com/white-the-Alan/p/9351712.html
Copyright © 2011-2022 走看看