【问题标题】:Workaround for get_serving_url not supporting width/height 'size' param?get_serving_url 不支持宽度/高度“大小”参数的解决方法?
【发布时间】:2012-04-03 10:14:21
【问题描述】:
【问题讨论】:
标签:
python
google-app-engine
blobstore
【解决方案2】:
您需要做的是计算原始图像的比例以将其调整为所需的宽度和高度,然后您应该将计算出的尺寸值传递给服务网址并获得您想要的。
resolution = '1200x900'
blob_width, blob_height = resolution.split('x')
blob_width = float(blob_width)
blob_height = float(blob_height)
width = float(width)
height = float(height)
blob_prop = blob_width / blob_height
req_box_prop = width / height
if req_box_prop == blob_prop:
scale_factor = blob_width / width
serving_img_height = blob_width / scale_factor
serving_img_width = blob_height / scale_factor
if req_box_prop < blob_prop:
serving_img_width = width
serving_img_height = width / blob_prop
else:
serving_img_width = height * blob_prop
serving_img_height = height
serving_img_width = int(round(serving_img_width, 0))
serving_img_height = int(round(serving_img_height, 0))
# use serving urls
side = max(serving_img_width, serving_img_height)
side 是您用于服务网址的内容
'http://yourservingurl=s%s'%side