Si la imagen se almacena en una BlobProperty, a continuación, los datos se almacenan en el almacén de datos, y si profile
es su entidad, la altura es posible acceder a:
from google.appengine.api import images
height = images.Image(image_data=profile.avatar).height
Si la imagen está en el blobstore, (blobstore.BlobReferenceProperty en el almacén de datos), entonces usted tiene 2 formas de hacerlo, la mejor manera es complicada y requiere obtener un lector para el blob y alimentarlo a un lector exif para obtener el tamaño. Una forma más fácil es:
si avatar = db.BlobReferenceProperty()
y profile
es su entidad, entonces:
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
puede también mostrar el mejor método/complicada, así que aquí? – Lipis
guau increíble. Me preguntaba por qué no podía obtener el ancho –