[英]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: 有三个原因:
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.