我使用GAE上傳圖片,並使用google.appengine.api.images來調整尺寸。但是我想獲取這張圖片的原始尺寸upload.i嘗試使用image.width和image.height.but得到int不可調用error.soi感謝任何幫助。如何獲取GAE上傳的圖片尺寸
請參閱下面的代碼:你看image_.size
class PictureUploader(webapp.RequestHandler):
WANNA_RATIO_ = 0.833333 # icon width : height | 100 : 120
MAX_RATIO_ = 0.913043 # 105 : 115
MIN_RATIO_ = 0.76 # 95 : 125
def get(self):
self.post()
def post(self):
if not check_session(self):
self.redirect('login', True)
from google.appengine.api import images
image_ = images.Image(self.request.get('picture'))
from decimal import Decimal
i_width = Decimal(image_.size[0])
i_height = Decimal(image_.size[1])
w_h_ratio = i_width/i_height
if PictureUploader.MIN_RATIO_ > w_h_ratio: # picture too narrow
h_ratio = i_height/120
expected_w = Decimal("%.6f"%(i_width/h_ratio))
image_ = images.resize(image_,expected_w,120)
elif PictureUploader.MAX_RATIO_ < w_h_ratio: # picture too short
w_ratio = i_width/100
expected_h = Decimal("%.6f"%(i_height/w_ratio))
image_ = images.resize(image_,100,expected_h)
else:
image_ = images.resize(image_, 100, 120)
models.Life(user = self.session['key'],pictureblob=image_).put()
[0],這是行不通的。
錯誤'int是不是callable'似乎表明您意外後放在()屬性名,即你有'image.height()'它應該只是'image.height' –