本文實(shí)例講述了Python實(shí)現(xiàn)獲取本地及遠(yuǎn)程圖片大小的方法。分享給大家供大家參考,具體如下:
了解過Pillow的都知道,Pillow是一個(gè)非常強(qiáng)大的圖片處理器,這篇文章主要記錄一下Pillow對(duì)圖片信息的獲?。?/p>
安裝Pillow
pip install pillow
本地圖片
# -*- coding:utf-8 -*-#! python2import osfrom PIL import Imagepath = os.path.join(os.getcwd(),"23.png")img = Image.open(path)print img.format # PNGprint img.size # (3500, 3500)
遠(yuǎn)程圖片
# -*- coding:utf-8 -*-#! python2import urllib2import cStringIOfrom PIL import Imagepath = "http://h.hiphotos.baidu.com/image/pic/item/c8ea15ce36d3d5397966ba5b3187e950342ab0cb.jpg"file = urllib2.urlopen(path)tmpIm = cStringIO.StringIO(file.read())img = Image.open(tmpIm)print img.format # JPEGprint img.size # (801, 1200)
運(yùn)行結(jié)果如下圖:

更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python數(shù)學(xué)運(yùn)算技巧總結(jié)》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
網(wǎng)友關(guān)注