Home  >  Article  >  Backend Development  >  How to read image size in python

How to read image size in python

尚
Original
2019-07-10 11:21:457157browse

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 the Python Tutorial column 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn