python 利用PIL庫變更圖片大小的操作

來源:互聯網
上載者:User

標籤:pillow   出圖   main   ali   img   idt   簡單   import   簡寫   

python 是可以利用PIL庫變更圖片大小的操作的,當然一般情況下是不需要的,但是在一些特殊的利用場合,是需要改變圖片的灰階或是大小等的操作的,其實用python更改圖片的大小還是蠻簡單的,只需要幾行代碼,有一點可能剛入門的小夥伴們可能不知道PIL庫,PIL是一個庫的簡寫,他的真名叫做pillow,因此,需要pip install pillow 用anaconda的話是conda install pillow千萬不要pip/conda install PIL咯,下面貼出代碼,希望對一些小夥伴們能有協助

#encoding=utf-8import osimport os.pathfrom PIL import Image‘‘‘filein: 輸入圖片fileout: 輸出圖片width: 輸出圖片寬度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\test.png‘  fileout = r‘image\testout.png‘  width = 60  height = 85  type = ‘png‘  ResizeImage(filein, fileout, width, height, type)

  

python 利用PIL庫變更圖片大小的操作

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.