1

我使用 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],它不起作用。

4

1 回答 1

1

利用

image.height
image.width

您收到的错误意味着您正在调用这些属性,例如:

image.height() -> wrong
image.width()  -> wrong
于 2012-10-17T16:24:32.787 回答