GAE:如何获得blob-image高度 [英] GAE: How to get the blob-image height
问题描述
avatar = db.BlobProperty()
通过调用图像实例属性的高度或宽度(
height
引发以下错误:
AttributeError:'Blob'对象没有'height'属性
PIL如果图像存储在BlobProperty中,那么数据存储在数据存储中,如果<$ c $ c> profile 是您的实体,那么您可以以如下方式访问该高度:
from google。 appengine.api import images
height = images.Image(image_data = profile.avatar).height
如果图像在t中他blobstore(数据存储区中的blobstore.BlobReferenceProperty),那么你有2种方法来实现它,更好的方法是复杂的,并且需要获取blob的读取器并将其提供给exif reader以获取大小。一个简单的方法是:如果 / code>是您的实体,那么: Given is the follwing model on GAE: By calling the image instance properties height or width (see documentation) with: the following error is thrown: AttributeError: 'Blob' object has no attribute 'height' PIL is installed. If the image is stored in a BlobProperty, then the data is stored in the datastore, and if If the image is in the blobstore, (blobstore.BlobReferenceProperty in the datastore), then you have 2 ways of doing it, the better way is complicated and requires getting a reader for the blob and feeding it to a exif reader to get the size. An easier way is: if
这篇关于GAE:如何获得blob-image高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! avatar = db.BlobReferenceProperty()
和 profile
from google.appengine.api import images
img = images.Image(blob_key = str(profile.avatar.key()))
#我们必须执行一个变换来访问宽度/高度
img.im_feeling_lucky()#做一个变换,否则GAE抱怨。
#将质量设置为1,如果图像很大,结果将适合1MB
img.execute_transforms(output_encoding = images.JPEG,quality = 1)
#现在你可以访问img.height和img.width
avatar = db.BlobProperty()
height = profile.avatar.height
profile
is your entity, then the height can be accessed as:from google.appengine.api import images
height = images.Image(image_data=profile.avatar).height
avatar = db.BlobReferenceProperty()
and profile
is your entity, then: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