Python實(shí)現(xiàn)更改圖片尺寸大小的方法(基于Pillow包)
本文實(shí)例講述了Python實(shí)現(xiàn)更改圖片尺寸大小的方法。分享給大家供大家參考,具體如下:
1、PIL包推薦Pillow 。
2、源碼:
#encoding=utf-8 #author: walker #date: 2014-05-15 #function: 更改圖片尺寸大小 import os import os.path from 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)
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
淺談python3 構(gòu)造函數(shù)和析構(gòu)函數(shù)
這篇文章主要介紹了淺談python3 構(gòu)造函數(shù)和析構(gòu)函數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-03-03
巧妙使用Python裝飾器處理if...elif...else
大家好,今天在 Github 閱讀 EdgeDB[1] 的代碼,發(fā)現(xiàn)它在處理大量if…elif…else的時(shí)候,巧妙地使用了裝飾器,方法設(shè)計(jì)精巧,分享給大家一下,歡迎收藏學(xué)習(xí),喜歡點(diǎn)贊支持2021-11-11
使用python的pandas庫讀取csv文件保存至mysql數(shù)據(jù)庫
這篇文章主要介紹了利用python的pandas庫讀取csv文件保存至mysql數(shù)據(jù)庫的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-08-08

