0

我正在尝试使用 google.appengine.api.images 裁剪图像。

不幸的是,尝试使用这些参数裁剪尺寸为 612x612 的图像返回 None:

(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)
4

1 回答 1

2

您需要使用 execute_transforms 方法,该方法将在指定所有图像操作后返回图像。指定裁剪只是将该操作添加到要执行的操作队列中,并且不会在该点返回图像实例。

所以你会做'img_cropped = img.execute_transforms()'

查看图像服务概述文档中的示例https://developers.google.com/appengine/docs/python/images/overview

于 2012-08-27T14:23:26.507 回答