处理来自blob GAE的图像 [英] Processing image from the blob GAE

查看:126
本文介绍了处理来自blob GAE的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法在Google App引擎Blob中存储了一张图片(我可以从仪表板中的Blob查看器中看到它,也可以在我的应用中使用服务处理程序)。
但是,现在我已经这张照片在那里......我想调整它的大小,同时提供给客户端...问题是我不能这样做......我无法将图像从该blob中取出......这是我的代码:

  from google.appengine.api从google.appengine.ext导入图片

导入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()#做一个转换,否则GAE会抱怨。

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:如何获得blob-image高度



当我运行上面的代码时,ex / img / 373 i获取错误:

图像http:.... / img / 373无法显示,因为它包含错误
我该如何做到这一点?..我想要的是找出方法来转换图像中的blob,然后处理图像...

解决方案

您不需要通过应用程序管理该图像。
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 价值
到该网址,你就完成了。


I managed to store a picture in the Google App engine blob (I can see it in the Blob Viewer from the dashboard, and also in my app using a serving handler).. However, now that i have this picture there..i want to resize it while serving it to the client...Problem is that i can't do that...I can't make an Image out of that blob...This is my code :

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)

The code from above is taken from this thread : GAE: How to get the blob-image height

When i run the code from above ex /img/373 i get the error :

The image "http:..../img/373" cannot be displayed because it contains errors How can i do this ?..What i want is to find out way to transform that blob in an image and then process the image...

解决方案

You don't need to pipe that image through your application. The gae has a service for resizing images:

from google.appengine.api.images import get_serving_url
url = get_serving_url( "blobkey")

Then append one of https://developers.google.com/appengine/docs/python/images/functions#imgsize values to that url and you're done.

这篇关于处理来自blob GAE的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆