【发布时间】:2013-04-06 12:09:54
【问题描述】:
我设法在 Google App 引擎 blob 中存储了一张图片(我可以在仪表板的 Blob 查看器中看到它,也可以在我的应用程序中使用服务处理程序看到它).. 但是,现在我有这张图片了..我想在为客户提供服务时调整它的大小...问题是我不能这样做...我不能用那个 blob 制作图像.. .这是我的代码:
from google.appengine.api import images
from google.appengine.ext import blobstore
from google.appengine.ext.webapp import blobstore_handlers
....
class Image(webapp2.RequestHandler):
def get(self,id):
product = Product.by_id(int(id))
logging.info('pic key is' + str(product.small_pic.key()))
img = images.Image(blob_key=str(product.small_pic.key()))
img.im_feeling_lucky() # do a transform, otherwise GAE complains.
img.execute_transforms(output_encoding=images.JPEG,quality=1)
if img:
self.response.headers['Content-Type'] = 'image/png'
self.response.out.write(img)
else:
self.error(404)
上面的代码取自这个线程:GAE: How to get the blob-image height
当我从上面的 ex /img/373 运行代码时,我得到了错误:
图片“http:..../img/373”无法显示,因为它包含错误 我该怎么做?..我想要找到在图像中转换该 blob 的方法,然后处理图像...
【问题讨论】:
-
在
execute_transforms中,您将编码指定为JPEG,并在响应标头中将其指定为PNG。这应该是? -
在我的许多尝试中,我评论了
img.execute_transforms(output_encoding=images.JPEG,quality=1)这一行,但仍然没有任何改变:(
标签: python image google-app-engine blob