Home>Article>Backend Development> How to read image size in python
Python can obtain image size information through pillow,
Getting method:
Install pillow:
pip install pillow
Get Local image information:
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)
Get remote image information:
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)
For more Python related technical articles, please visit thePython Tutorialcolumn to learn!
The above is the detailed content of How to read image size in python. For more information, please follow other related articles on the PHP Chinese website!