简体   繁体   English

使用EC2根据需要调整存储在S3上的图像

[英]Using EC2 to resize images stored on S3 on demand

We need to serve the same image in a number of possible sizes in our app. 我们需要在我们的应用中以多种可能的尺寸提供相同的图像。 The library consists of 10's of thousands of images which will be stored on S3, so storing the same image in all it's possible sizes does not seem ideal. 该库由数以万计的图像组成,这些图像将存储在S3上,因此以相同的尺寸存储相同的图像似乎并不理想。 I have seen a few mentions on Google that EC2 could be used to resize S3 images on the fly, but I am struggling to find more information. 我在Google上看到过一些提及EC2可以用来动态调整S3图像的大小,但我很难找到更多信息。 Could anyone please point me in the direction of some more info or ideally, some code samples? 任何人都可以指向一些更多信息的方向或理想情况下,一些代码示例?

Tip 小费

It was not obvious to us at first, but never serve images to an app or website directly from S3, it is highly recommended to use CloudFront. 一开始对我们来说并不明显,但从不直接从S3向应用或网站提供图像,强烈建议使用CloudFront。 There are 3 reasons: 有三个原因:

  1. Cost - CloudFront is cheaper 成本 - CloudFront更便宜
  2. Performance - CloudFront is faster 性能 - CloudFront更快
  3. Reliability - S3 will occasionally not serve a resource when queried frequently ie more than 10-20 times a second. 可靠性 - S3经常在查询时偶尔不会提供资源,即每秒超过10-20次。 This took us ages to debug as resources would randomly not be available. 这需要我们多年的时间来调试,因为资源随机无法使用。

The above are not necessarily failings of S3 as it's meant to be a storage and not a content delivery service. 以上不一定是S3的失败,因为它意味着存储而不是内容传递服务。

Why not store all image sizes, assuming you aren't talking about hundreds of different possible sizes? 假设您没有谈论数百种不同的可能尺寸,为什么不存储所有图像尺寸? Storage cost is minimal. 存储成本极低。 You would also then be able to serve your images up through Cloudfront (or directly from S3) such that you don't have to use your application server to resize images on the fly. 然后,您还可以通过Cloudfront(或直接从S3)提供图像,这样您就不必使用应用程序服务器即时调整图像大小。 If you serve a lot of these images, the amount of processing cost you save (ie CPU cycles, memory requirements, etc.) by not having to dynamically resize images and process image requests in your web server would likely easily offset the storage cost. 如果您提供大量这些图像,则无需在Web服务器中动态调整图像和处理图像请求,节省的处理成本(即CPU周期,内存要求等)可能很容易抵消存储成本。

What you need is an image server. 你需要的是一个图像服务器。 Yes, it can be hosted on EC2. 是的,它可以在EC2上托管。 These links should help starting off: https://github.com/adamdbradley/foresight.js/wiki/Server-Resizing-Images http://en.wikipedia.org/wiki/Image_server 这些链接应该有助于开始: https//github.com/adamdbradley/foresight.js/wiki/Server-Resizing-Images http://en.wikipedia.org/wiki/Image_server

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 缩放存储在S3的图像 - Scaling images stored at S3 调整存储在数组中的所有图像的大小 - Resize all images stored in array 使用AWS Lambda,Amazon API Gateway快速调整S3映像的大小 - HTML IMG标记的重定向过多 - Resize S3 Images on the Fly with AWS Lambda, Amazon API Gateway - too many redirects for HTML IMG tag 图像使用Node.js从Amazon S3动态调整大小 - Image Resize on the fly from Amazon S3 using Node.js 是否可以在不使用浏览器内置的 canvas 实现的情况下调整存储在 Uint8Array 中的图像的大小? - Is it possible to resize an image that is stored in a Uint8Array without using the browser's built-in canvas implementation? Codeignter的图像处理(使用GD库)不会调整某些JPEG图像的大小 - Codeignter's image manipulation(using GD library) doesn't resize some JPEG images 在 Amazon S3 中上传带有恶意代码的图像 - Uploaded images with malicious code in Amazon S3 从Amazon S3采购缓存的图像 - Sourcing Cached Images from Amazon S3 Meteor CollectionFS:S3 GraphicsMagick不会调整图像大小 - Meteor CollectionFS:S3 GraphicsMagick Does Not Resize Image 耗尽系统处理使用 WPF 调整图像大小 - Exhausting system handles using WPF to resize images
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM