日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

Python中獲取圖片的大小問(wèn)題_python

作者:玉米叢里吃過(guò)虧 ? 更新時(shí)間: 2022-12-26 編程語(yǔ)言

Python獲取圖片的大小

了解過(guò)Pillow的都知道,Pillow是一個(gè)非常強(qiáng)大的圖片處理器,這篇文章主要記錄一下Pillow對(duì)圖片信息的獲取:

安裝Pillow

pip install pillow

本地圖片

import os
from PIL import Image

path = os.path.join(os.getcwd(),"23.png")
img = Image.open(path)

print img.format ? ? ? ?# PNG
print img.size ? ? ? ? ?# (3500, 3500)

遠(yuǎn)程圖片

path = "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 ? ? ? ? # JPEG
print img.size ? ? ? ? ? # (801, 1200)

Python不加載圖片獲取尺寸

解釋

網(wǎng)上其他人的說(shuō)法基本都不太可行,恭喜你找到了寶藏。

通常在 Python 里讀取尺寸時(shí)都會(huì)把整張圖片加載到內(nèi)存中,非常耗時(shí),有沒(méi)有辦法像 Andorid 加載 Bitmap 時(shí)一樣快速讀取尺寸而不加載圖片呢?答案是有的,使用 imagesize。

例子

下載

pip install imagesize

使用

import imagesize


def main():
?? ?input_path = ''
?? ?width, height = imagesize.get(input_path)


if __name__ == '__main__':
?? ?main()

原文鏈接:https://blog.csdn.net/y472360651/article/details/79272927

欄目分類(lèi)
最近更新