我设法将图片存储在 Google App 引擎 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:如何获取斑点图像高度 https://stackoverflow.com/questions/4796793/gae-how-to-get-the-blob-image-height/4798806#4798806
当我运行上面的代码 ex /img/373 时,我收到错误:
无法显示图像“http:..../img/373”,因为它包含错误我该怎么做?...我想要的是找到方法来转换图像中的斑点,然后处理图像...
您不需要通过应用程序传输该图像。
gae 有一个调整图像大小的服务:
from google.appengine.api.images import get_serving_url
url = get_serving_url( "blobkey")
然后附加其中之一https://developers.google.com/appengine/docs/python/images/functions#imgsize https://developers.google.com/appengine/docs/python/images/functions#imgsize价值观
到那个网址就完成了。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)