Skip to main content
 首页 » 编程设计

python之在 blobstore webapp2 上存储调整大小的图像

2025年02月15日34mfrbuaa

我已经使用 GAE 图像 api 成功地调整了图像大小,现在我再次想将调整后的图像存储在 blob-store 中,请问我该怎么做,请帮忙。这是代码

img = images.Image(blob_key=user.profile_pic) 
img.resize(width=80, height=100) 
img.im_feeling_lucky() 
thumbnail = img.execute_transforms(output_encoding=images.JPEG) 

如果我使用此代码,它会显示调整大小的图像,但我想再次将其存储在 blob 存储中。

self.response.headers['Content-Type'] = 'image/jpeg' 
self.response.out.write(thumbnail) 

请您参考如下方法:

解决方法是获取服务url后,我们可以简单地在链接中传递参数来对图像进行操作。

img = images.Image(blob_key=user.profile_pic) 
url = images.get_serving_url(user.profile_pic)         
url = url + "=s80" #if i want a thumbnail