Boa*_*oaz 6 python python-imaging-library
使用 PIL 确定图像的宽度和高度
在特定图像上(幸运的是只有这一个 - 但它令人不安)从 image.size 返回的宽度/高度是相反的。图片: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
Run Code Online (Sandbox Code Playgroud)
结果是 -(2592, 1936)
应该是相反的
这样做的原因是该图像具有与其关联的ExifOrientation元数据,这将导致尊重该属性的应用程序旋转它:
# identify -verbose IMG_0004.JPG | grep Orientation
Orientation: RightTop
exif:Orientation: 6
Run Code Online (Sandbox Code Playgroud)
与普通图像比较:
# identify -verbose iceland_pano.jpg | grep Orientation
Orientation: TopLeft
exif:Orientation: 1
Run Code Online (Sandbox Code Playgroud)
所以图像尺寸实际上是横向的(宽大于高),但它会被浏览器、图像查看器等旋转显示。
| 归档时间: |
|
| 查看次数: |
4109 次 |
| 最近记录: |