2012-08-27 84 views
0

我想使用google.appengine.api.images裁剪圖像。Appengine圖像裁剪工具返回無

不幸的是試圖與這些參數與大小612x612裁剪圖像返回無:

(0.0, 0.14052287581699346, 1.0, 0.85947712418300659) 

它不生成異常或任何有意義的錯誤消息;只是一個無返回值。

有什麼想法?

編輯:

以下是我使用的全部代碼:

path = urllib.unquote(path) 
r = urllib.urlopen(path) 
image_data = r.read() 
img = Image(image_data = image_data) 
width, height = float(img.width), float(img.height) 
max_height = 440.0 
max_width = 940.0 

rest_height = 0.0 
if height > max_height: 
    rest_height = height - max_height 

rest_width = 0.0 
if width > max_width: 
    rest_width = width - max_width 

left_x = rest_width/(2 * width) 
top_y = rest_height/(2 * height) 
right_x = 1.0 - left_x 
bottom_y = 1.0 - top_y 

img_cropped = img.crop(left_x,top_y,right_x,bottom_y) 

回答

2

您需要使用execute_transforms方法,這將在所有的圖像操作的指定返回圖像。指定裁剪只是將該操作添加到要執行的操作隊列中,並且不會在該點返回圖像實例。

所以,你會做「img_cropped = img.execute_transforms()」

看看一個例子在概述文檔的圖像服務https://developers.google.com/appengine/docs/python/images/overview

+0

謝謝!這是我尋找的解決方案:) – fstab