Nếu hình ảnh được lưu trữ trong một BlobProperty, sau đó dữ liệu được lưu trữ trong kho dữ liệu, và nếu profile
là thực thể của bạn, sau đó chiều cao có thể được truy cập như:
from google.appengine.api import images
height = images.Image(image_data=profile.avatar).height
Nếu hình ảnh là trong blobstore, (blobstore.BlobReferenceProperty trong kho dữ liệu), sau đó bạn có 2 cách để làm nó, cách tốt hơn là phức tạp và đòi hỏi phải có một người đọc cho blob và cho nó vào một đầu đọc exif để có được kích thước. Một cách dễ dàng hơn là:
nếu avatar = db.BlobReferenceProperty()
và profile
là thực thể của bạn, sau đó:
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
bạn cũng có thể hiển thị tốt hơn/phương pháp phức tạp cũng như ở đây? – Lipis
wow tuyệt vời. Tôi đã tự hỏi tại sao tôi không thể có được chiều rộng –