Home > Backend Development > Python Tutorial > How to read image size in python

How to read image size in python

Release: 2019-07-10 11:21:45
Original
7281 people have browsed it

How to read image size in python

Python can obtain image size information through pillow,

Getting method:

Install pillow:

pip install pillow
Copy after login

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)
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template