生成 PNG 作为 HTTP 响应的最有效方法

发布于 2024-09-05 20:33:01 字数 217 浏览 5 评论 0原文

我构建了一个 ASP.NET 页面,其输出流是动态生成的 PNG 图像,仅包含透明背景上的文本。

该文本基于查询字符串中包含的数据库 ID。会有有限数量的变化。

以下哪一项是将图像返回给客户端的最有效方法?

  1. 将每个变体存储在第一代上,然后从驱动器中检索它。
  2. 每次只需生成图像即可。
  3. 根据查询字符串缓存输出响应。

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?

  1. Store each variation upon the first generation, and thenceforth retrieve this from the drive.
  2. Simply generate the image each time.
  3. Cache the output response based upon the querystring.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼前雾蒙蒙 2024-09-12 20:33:01

完全取决于生成该图像的频率。

如果这是一个小项目,我会选择每次生成它,因为这将是最简单的解决方案。

如果您期望生成很多代,那么每次生成图像时都存储图像,然后检查预生成的图像,但它会变得有点复杂,这一切都取决于您期望生成多少个独特的图像变体,如果它很小,就用它,否则你可能不得不在不经常访问的图像上设置过期日期。

简而言之,这取决于它的应用是什么,并且没有提供足够的信息来对您的具体解决方案给出全面的答案。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文