谷歌AppEngine图像API突然破坏图像

时间:2013-05-06 19:33:52

标签: python image api google-app-engine

过去一年,我们一直在使用AppEngine的图像API。突然在过去一周左右,图像API似乎破坏了图像。我们使用图像API执行一些不同的操作,但似乎导致问题的是我们对TIFF数据执行images.rotation(0)以将其转换为PNG。 (我们还没有尝试过其他文件类型的转换,但关键是这个工作超过一年了,为什么它会突然停止工作?此外,我们需要它与TIFF一起工作到PNG,因为TIFF是入站数据的格式)

很长一段时间没有问题,今天突然发现任何经过这个过程的TIFF在输出时都会被破坏。它看起来好像是加倍和倾斜。

这是在AppEngine 1.7.7上使用Python 2.7 API。我们直接使用Google图片API,而不是通过PIL。

请帮忙!这正在扼杀我们的生产环境。

示例代码:

from google.appengine.api import images
import webapp2

def get_sample():
    # sample.tiff is a 1bit black and white group3 tiff from a fax service
    with open("sample.tiff") as x: 
        f = x.read()
    return f

class MainHandler(webapp2.RequestHandler):
    def get(self):
        # Convert to PNG using AppEngine's images API by doing a rotation of 0 degrees.
        # This worked fine for over a year and now suddenly started corrupting the 
        # output image with a grainy double image that looks like two of the 
        # same image are layered on top of each other and vibrating.
        sample = get_sample()
        png = images.rotate(sample, 0)

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

application = webapp2.WSGIApplication([('/', MainHandler)], debug=True)

3 个答案:

答案 0 :(得分:1)

原来,这是由于最近对图像API的更改导致了一个影响TIFF文件操作的错误,该错误已经被恢复。更多信息在最初的错误报告中。

https://code.google.com/p/googleappengine/issues/detail?id=9284

答案 1 :(得分:0)

阅读here

  

度       以90度的倍数旋转图像的量,以度数表示。必须是int或long。

你可以试试吗

png = images.rotate(sample, 360)

如果这不起作用,请尝试(基本上每次旋转180度,以便清除原始帧)

png1 = images.rotate(sample, 180)
png = images.rotate(png1, 180)

希望有所帮助

答案 2 :(得分:0)

我一直用它来加载图像,我不使用tiff图像,但这可能是我想的问题 - 也许用PIL来转换图像?

class Image(BaseHandler):
    def get(self):
        employee = clockin.Employee.get(self.request.get("img_id"))
        if employee.avatar:
            self.response.headers['Content-Type'] = "image/png"
            image = images.resize(employee.avatar, 150, 150)
            self.response.out.write(image)
        else:
            self.response.out.write("No image")