7

我将使用 S3 来存储用户上传的照片。显然,我不会在不调整大小的情况下将图像文件提供给用户代理。但是,没有一种尺寸可以,因为一些缩略图会比其他较大的预览小。因此,我正在考虑制作一组标准尺寸,从最低的 16x16 缩放到最高的 1024x1024。这是解决这个问题的好方法吗?如果我以后需要新尺寸怎么办?你会如何解决这个问题?

4

2 回答 2

14

Pre-generating different sizes and storing them in S3 is a fine approach, especially if you know what sizes you need, are likely to use all of the sizes for all of the images, and don't have so many images and sizes that the storage cost is excessive.

Here's another approach I use when I don't want to pre-generate and store all the different sizes for every image, or when I don't know what sizes I will want to use in the future:

  1. Store the original size in S3.

  2. Run a web server that can generate any desired size from the original image on request.

  3. Stick a CDN (CloudFront) in front of the web server.

Now, your web site or application can request a URL like /16x16/someimage.jpg from CloudFront. The first time this happens, CloudFront will get the resized image from your web server, but then CloudFront will cache the image and serve it for you, greatly reducing the amount of traffic that hits your web server.

Here's a service that resizes images from arbitrary URLs, serving them through CloudFront: http://filter.to

于 2012-10-21T20:30:29.020 回答
0

这听起来是个不错的方法。根据您的应用程序,您应该定义一组始终生成的缩略图大小。但也存储原始用户文件,如果您的要求稍后更改。当您想要添加新的缩略图大小时,您可以遍历所有原始文件并从中生成新的缩略图。此选项为您提供了以后的灵活性。

于 2012-10-20T07:04:07.777 回答