2011-01-25 9 views
6

को देखते हुए प्राप्त करने के लिए GAE पर follwing मॉडल है:GAE: कैसे ब्लॉब छवि ऊंचाई

height = profile.avatar.height 

:

avatar = db.BlobProperty() 

के साथ छवि उदाहरण गुण ऊंचाई या चौड़ाई (see documentation) पर कॉल करके निम्नलिखित त्रुटि फेंक दी गई है:

AttributeError: 'Blob' object has no attribute 'height'

पीआईएल स्थापित है।

उत्तर

13

छवि एक BlobProperty में जमा हो जाती है, तो डेटा डेटासंग्रह में संग्रहीत किया जाता है, और अगर profile अपने इकाई है, तो ऊंचाई के रूप में पहुँचा जा सकता है: अगर छवि में है

from google.appengine.api import images 
height = images.Image(image_data=profile.avatar).height 

ब्लॉबस्टोर, (डेटाबोर में ब्लॉबस्टोर.ब्लोब रेफरेंसप्रोपर्टी), तो आपके पास इसे करने के 2 तरीके हैं, बेहतर तरीका जटिल है और इसे ब्लॉब के लिए पाठक प्राप्त करने और आकार प्राप्त करने के लिए इसे एक एक्फिफ़ रीडर को खिलााना आवश्यक है। एक आसान तरीका है:

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 
+1

तुम भी रूप में अच्छी तरह यहां बेहतर/जटिल विधि दिखा सकते हैं? – Lipis

+0

वाह अद्भुत। मैं सोच रहा था कि मुझे चौड़ाई क्यों नहीं मिल सका –

5

एक ब्लॉब छवि नहीं है, यह डेटा का एक ढेर है।

आदेश में एक Image अपने ब्लॉब से बाहर करने के लिए, आप Image(blob_key=your_blob_key) कॉल करने के लिए अगर आपके ब्लॉब या Image(image_data=your_image_data) Blobstore में संग्रहीत किया जाता है, अगर यह डेटासंग्रह में एक ब्लॉब के रूप में जमा रहा है।

संबंधित मुद्दे