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

2024-10-02 04:23:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我用GAE上传图片,并使用谷歌.appengine.api.要调整大小的图像它。但是我想上传这张照片的原始尺寸。我试着用图像.宽度以及图像。高度。但是got int不可调用错误.soi谢谢你的帮助。在

请参见以下代码:

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


Tags: 图像imageselfapiwidthexpecteddecimalimages
1条回答
网友
1楼 · 发布于 2024-10-02 04:23:09

使用

image.height
image.width

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

^{pr2}$

相关问题 更多 >

    热门问题