你需要做的是計算原始圖像的比例,以調整它到你想要的寬度和高度,之後,你應該有計算的大小值傳遞到服務的網址,並得到你想要的。
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)
和側面是你用什麼爲您服務網址
'http://yourservingurl=s%s'%side
也許你應該出演這個問題以及 - HTTP ://code.google.com/p/googleappengine/issues/detail?id = 4200 – 2012-04-06 12:48:39