PIL Image.size返回相反的宽度/高度 [英] PIL Image.size returns the opposite width/height
问题描述
使用PIL确定图像的宽度和高度
Using PIL to determine width and height of images
在一个特定的图像上(幸运的是,只有一个-但是很麻烦),从image.size返回的宽度/高度是相反的.
图片:
http://storage.googleapis.com/cookila-533ebf752b9d1f7c1e8b4db3/IMG_0004.JPG
On a specific image (luckily only this one - but it is troubling) the width/height returning from image.size is the opposite.
The image:
http://storage.googleapis.com/cookila-533ebf752b9d1f7c1e8b4db3/IMG_0004.JPG
代码:
from PIL import Image
import urllib, cStringIO
file = cStringIO.StringIO(urllib.urlopen('http://storage.googleapis.com/cookila-533ebf752b9d1f7c1e8b4db3/IMG_0004.JPG').read())
im=Image.open(file)
print im.size
结果是-(2592, 1936)
应该相反
The result is - (2592, 1936)
should be the other way around
推荐答案
The reason for this is that this image has Exif Orientation
metadata associated with it that will cause applications that respect that property to rotate it:
# identify -verbose IMG_0004.JPG | grep Orientation
Orientation: RightTop
exif:Orientation: 6
与常规图像比较:
# identify -verbose iceland_pano.jpg | grep Orientation
Orientation: TopLeft
exif:Orientation: 1
因此图像尺寸实际上是横向的(宽于高),但是会在浏览器,图像查看器等显示时旋转.
So the image dimensions are actually landscape (more wide than high), but it will get rotated on display by browsers, image viewers etc.
这篇关于PIL Image.size返回相反的宽度/高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!