Compress GAE Blob images using Python Base64?

非 Y 不嫁゛ 提交于 2019-12-06 12:10:48

Yes, encoding the images directly using base64 seems like a reasonable approach, given they're only thumbnails. This is similar to using data: URLs in a webpage for the same reason.

Doing it should be as simple as calling the same Images API transforms you do in your regular code to generate the thumbnail, then serializing the resulting output as base64. You probably want to cache the result in memcache - in both handlers - to prevent redundant calls to the Images API. Alternately, you could calculate the thumbnail when the image is first uploaded, and store it alongside the full-size image.

Perhaps you just need to call read()

encoded = item.image.read().encode('base64')

If you're dealing with images of any great size, you'll want to encode in chunks (i.e. read(4096) multiple times, encoding each piece).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!