给出了 GAE 上的以下模型:
avatar = db.BlobProperty()
通过调用图像实例属性 height 或 width (查看文档 http://code.google.com/appengine/docs/python/images/imageclass.html#Image_height) with:
height = profile.avatar.height
抛出以下错误:
AttributeError:“Blob”对象没有属性“height”
PIL 已安装。
如果图像存储在 BlobProperty 中,则数据存储在数据存储中,并且如果profile
是你的实体,那么高度可以通过以下方式访问:
from google.appengine.api import images
height = images.Image(image_data=profile.avatar).height
如果图像位于 blobstore 中(数据存储中的 blobstore.BlobReferenceProperty),则有 2 种方法可以实现,更好的方法比较复杂,需要获取 Blob 读取器并将其提供给 exif 读取器以获取大小。一个更简单的方法是:
if avatar = db.BlobReferenceProperty()
and profile
是你的实体,那么:
from google.appengine.api import images
img = images.Image(blob_key=str(profile.avatar.key()))
# we must execute a transform to access the width/height
img.im_feeling_lucky() # do a transform, otherwise GAE complains.
# set quality to 1 so the result will fit in 1MB if the image is huge
img.execute_transforms(output_encoding=images.JPEG,quality=1)
# now you can access img.height and img.width
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)