Dan*_*ean 6 python google-app-engine blob python-imaging-library
给出了GAE的后续模型:
avatar = db.BlobProperty()
Run Code Online (Sandbox Code Playgroud)
通过调用图像实例属性高度或宽度(请参阅文档):
height = profile.avatar.height
Run Code Online (Sandbox Code Playgroud)
抛出以下错误:
AttributeError:'Blob'对象没有属性'height'
PIL已安装.
Ami*_*mir 13
如果图像存储在BlobProperty中,则数据存储在数据存储区中,如果profile是您的实体,则可以访问高度:
from google.appengine.api import images
height = images.Image(image_data=profile.avatar).height
Run Code Online (Sandbox Code Playgroud)
如果图像在blobstore中(数据存储区中的blobstore.BlobReferenceProperty),那么你有两种方法可以做到这一点,更好的方法是复杂的,需要获取一个读取器的blob并将其提供给exif阅读器以获得大小.一种更简单的方法是:
如果avatar = db.BlobReferenceProperty()并且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
Run Code Online (Sandbox Code Playgroud)
blob不是图像,而是一块数据.
为了使Image你的blob脱离,你必须调用Image(blob_key=your_blob_key)你的blob存储在blobstore中,或者Image(image_data=your_image_data)它是否作为blob存储在数据存储区中.
| 归档时间: |
|
| 查看次数: |
1994 次 |
| 最近记录: |