如何获取GAE上传的图像大小

时间:2012-10-17 16:03:22

标签: python google-app-engine

我使用GAE上传图片,并使用google.appengine.api.images来调整它的大小。但我想要上传这张图片的原始大小。我尝试使用image.width和image.height。但得到int是不可调用的错误。感谢任何帮助。

请参阅以下代码:

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()

你看到image_.size [0],它不起作用。

1 个答案:

答案 0 :(得分:1)

使用

image.height
image.width

您获得的错误意味着您正在调用以下属性:

image.height() -> wrong
image.width()  -> wrong
相关问题