问题描述
我拉的20个随机缩略图的JSON请求到一个iPhone应用程序。目前,我只是包括JSON数组中的图像的URL拇指(见下文),那么iPhone熄灭获得每个图像。这实在是太慢了。
I'm pulling a JSON request of 20 random thumbnails to an iPhone application. At the moment I'm simply including the image thumb URLs in the JSON array (see below), then the iPhone goes out to get each image. This is really slow.
原始JSON请求:
{
"item_list": [
{
"item_name": "Item One",
"user_item_thumb": "http://localhost:8080/i/agpwaGluZ28tYXBwcg4LEghJdGVtVXNlchgPDA/67x67",
},
{
"item_name": "Item Two",
"user_item_thumb": "http://localhost:8080/i/agpwaGluZ28tYXBwcg4LEghJdGVtVXNlchgQDA/67x67",
},
{
"item_name": "Item Three",
"user_item_thumb": "http://localhost:8080/i/agpwaGluZ28tYXBwcg4LEghJdGVtVXNlchgRDA/67x67",
}
]
}
所以,我一直在用Base64编码的图像数据和思维实际上包括他们在JSON请求,所以iPhone只需要一个请求,而不是21个请求。合理?
So, what I was thinking was using Base64 on the image data and actually including them in the JSON request, so the iPhone only needs one request instead of 21 requests. Make sense?
那么,我该怎么做呢?结果
我想简单地打印到以下JSON,但那些都是全尺寸的图像,我需要按缩略图的Base64编码版本。
So, how do I do this?
I tried to simply print the below to JSON, but those are the full size images, I need to push a Base64 version of the Thumbnails.
不工作:
F = item.image结果
f_enc = f.en code('的base64')
这是如何得到我的拇指的那一刻,只是创建它们的飞行。
This is how I get my thumbs at the moment, just creating them on the fly.
这是什么使得上述图像请求:
This is what renders the above image request:
class Image(webapp.RequestHandler):
def get(self, image_id):
user = db.get(image_id)
if user.image:
picture = user.image
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(picture)
else:
self.response.out.write("No image")
任何想法,将是惊人的。结果
如果有更好的方法来做到这一点,我洗耳恭听。
Any ideas would be amazing.
If there's a better way to do this, I'm all ears.
我的问题:结果
- iPhone是缓慢的在每一个20幅图像的拉动结果
- 该图像是随机的,所以缓存可能不是一个选项结果。
- ?是Base64编码的路要走
My problems:
- The iPhone is slow pulling in each of these 20 images
- The images are random, so caching is probably not an option.
- Is Base64 the way to go?
谢谢,结果
丹尼
Thanks,
Danny
推荐答案
是的,直接编码图像使用Base64似乎是一个合理的做法,因为他们只是缩略图。这是类似于使用数据:
网址出于同样的原因网页
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.
这样做应该是为调用相同的图像API的简单转换,你对你的日常code做生成缩略图,然后序列化生成的输出为Base64。你可能想缓存结果在内存缓存 - 在这两个处理程序 - 以prevent冗余呼叫图片API。或者,你可以计算出的缩略图时,图像首先上传,并将其存储旁边的完整大小的图片。
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.
这篇关于使用Python的Base64 COM preSS GAE斑点图片吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!