生成 PNG 作为 HTTP 响应的最有效方法
我构建了一个 ASP.NET 页面,其输出流是动态生成的 PNG 图像,仅包含透明背景上的文本。
该文本基于查询字符串中包含的数据库 ID。会有有限数量的变化。
以下哪一项是将图像返回给客户端的最有效方法?
- 将每个变体存储在第一代上,然后从驱动器中检索它。
- 每次只需生成图像即可。
- 根据查询字符串缓存输出响应。
I've built an ASP.NET page whose output stream is a dynamically-generated PNG image containing only text on a transparent background.
The text is based upon database IDs contained in the querystring. There will be a limited number of variations.
Which one of the following would be the most efficient means of returning the image to the client?
- Store each variation upon the first generation, and thenceforth retrieve this from the drive.
- Simply generate the image each time.
- Cache the output response based upon the querystring.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完全取决于生成该图像的频率。
如果这是一个小项目,我会选择每次生成它,因为这将是最简单的解决方案。
如果您期望生成很多代,那么每次生成图像时都存储图像,然后检查预生成的图像,但它会变得有点复杂,这一切都取决于您期望生成多少个独特的图像变体,如果它很小,就用它,否则你可能不得不在不经常访问的图像上设置过期日期。
简而言之,这取决于它的应用是什么,并且没有提供足够的信息来对您的具体解决方案给出全面的答案。
Totally depends on how often this image is going to have to be generated.
If it's a small project I would elect to generate it each time as this would be the simplest solution.
If you are expecting a lot of generations then storing the image each time it's generated and checking for pre generated images would be next, it gets a bit complicated though, all depends on how many unique variations of images you expect to be generated, if it is small, go for it, otherwise you may have to have expiry dates on the images that are not so frequently accessed.
In short, it depends on what the application of this is, and not enough information was given to give a comprehensive answer to your specific solution.