Google App Engine PIL lib TypeError:“Image”类型的对象没有len()

时间:2011-02-18 08:49:27

标签: image google-app-engine

我想使用谷歌应用引擎的图像库裁剪图像。我正在使用的代码部分如下。

                key = self.request.get("blobkey")
                img = images.Image(str(key))
                images.crop(img,0.0,0.0,0.5,0.5)
                resim = img.execute_transforms(output_encoding=images.PNG)

        content = {
        }

        self.response.headers['Content-Type'] = "image/png"
        self.response.out.write(resim)

但是当我尝试裁剪图像时,会出现这样的错误。

                TypeError: object of type 'Image' has no len()

有没有人知道这个错误,还是有其他方法可以在python中裁剪图像?

提前致谢..

1 个答案:

答案 0 :(得分:1)

查看图片documentation

class Image(image_data=None, blob_key=None)

您忘记指定调用blob_key构造函数的Image名称参数:

key = self.request.get("blobkey")
img = images.Image(blob_key = str(key)) #You should specify blob_key
images.crop(img,0.0,0.0,0.5,0.5)
resim = img.execute_transforms(output_encoding=images.PNG)