通过即时调整大小服务图像 [英] Serving Images with on-the-fly resize

查看:127
本文介绍了通过即时调整大小服务图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司最近开始为我们网站的图像处理遇到问题。

my company has recently started to get problems with the image handling for our websites.

我们有几个网站(成人娱乐),可以显示dvd封面,快照等图片和类似的。我们有大约100,000部电影,每部电影我们平均有30部快照+封面。几乎每个图像都有一个额外的版本,模糊和覆盖非成员,这导致每部电影约50个图像或总共500万个基本图像。每个图像都有多个版本,具体取决于它放置在页面上的位置(缩略图,原始,小预览,不太小的预览,顶部列表中的小图像等),这会产生比图像更多的图像。我很想数数。

We have several websites (adult entertainment) that display images like dvd covers, snapshots and similar. We have about 100'000 movies and for each movie we have an average of 30 snapshots + covers. Almost every image has an additional version with blurring and overlay for non-members, this results in about 50 images per movie or a total of 5 million base images. Each of the images is available in several versions, depending on where it's placed on the page (thumbnail, original, small preview, not-so-small preview, small image in the top-list, etc.) which results in more images than i cared to count.

现在我有了使用服务器即时生成图像的想法,因为生成所有不同的图像变得十分笨拙所有不同的页面(因为不同的页面有时甚至需要不同的图像大小来完成相同的任务)。

Now i had the idea to use a server to generate the images on-the-fly since it became quite clumsy to generate all the different images for all the different pages (as different pages sometimes even need different image sizes for basically the same task).

有没有人知道可以缩小图像的图像处理服务器飞行所以我们只需要提供原始图像,网络人员可以只要求他们需要的大小吗?

Does anyone know of an image processing server that can scale down images on-the-fly so we only need to provide the original images and the web guys can just request whatever size they need?

要求:


  • 非常高的性能(每天数千名用户)

  • 即时模糊和叠加创建

  • 动态调整大小(有和没有保持宽高比)

  • 可以处理毫欧ns of images

  • 必须能够阅读JPG,GIF,PNG和BMP并在它们之间进行转换

  • Very High performance (Several thousand users per day)
  • On-the-fly blurring and overlay creation
  • On-the-fly resize (with and without keeping aspect ratio)
  • Can handle millions of images
  • Must be able to read JPG, GIF, PNG and BMP and convert between them

安全性并不是那么令人担忧,因为通过URL操作已经可以达到不模糊的图像,而且更安全性会很好但不是必需的并且坦率地说我停止了关注(在未能进入我的同事头之后为什么(对于我们的小型经销商页面)使用 http://示例是一个坏主意.com / view_image.php?filename = / data / images / 01020304.jpg 显示图像。。

Security is not that much of a concern as i.e. the unblurred images can already be reached by URL manipulation and more security would be nice but it's not required and frankly i stopped caring (After failing to get into my coworkers heads why (for our small reseller page) it's a bad idea to use http://example.com/view_image.php?filename=/data/images/01020304.jpg to display the images).

我们尝试使用PHP脚本执行此操作但是对于这么多用户来说,性能太慢了。

We tried PHP scripts to do this but the performance was too slow for this many users.

提前感谢你提出的任何建议。

Thanks in advance for any suggestions you have.

推荐答案

我建议您设置一个专用的Web服务器来处理图像大小调整并提供最终结果。我做了类似的事情,虽然规模要小得多。它基本上消除了检查缓存的过程。

I suggest you set up a dedicated web server to handle image resize and serve the final result. I have done something similar, although on a much smaller scale. It basically eliminates the process of checking for the cache.

它的工作原理如下:


  • 您请求将所需大小附加到文件名,如 http://imageserver/someimage.150x120.jpg

  • 如果图像存在,则返回时不进行其他处理(这是主要点,缓存检查是隐式的)

  • 如果图像不存在,则处理未找到的404 .htaccess并将请求重新路由到生成所需大小的映像的脚本

  • 在脚本中指定允许的大小列表,以避免攻击请求每个可能大小的脚本关闭服务器向下

  • 将此保留在无Cookie域上,以尽量减少不必要的流量

  • you request the image appending the required size to the filename like http://imageserver/someimage.150x120.jpg
  • if the image exists, it will be returned with no other processing (this is the main point, the cache check is implicit)
  • if the image does not exist, handle the 404 not found via .htaccess and reroute the request to the script that generates the image of the required size
  • in the script specify the list of allowed sizes to avoid attacks like scripts requesting every possible size to shut your server down
  • keep this on a cookieless domain to minimize unnecessary traffic

编辑:我不知道认为PHP本身会大大减慢这个过程,因为在这种情况下PHP脚本被减少到最小:图像缩放是由用C编写的内置库完成的。你应该使用像这样的库(GD或libmagick等),这是不可避免的。至少在我的系统中你完全省略了检查缓存的开销,从而进一步减少了PHP的交互。您可以在现有服务器上实现此功能,因此我认为这是一个非常适合您预算的解决方案。

I don't think that PHP itself would slow the process much, as PHP scripting in this case is reduced to a minimum: the image scaling is done by a builtin library written in C. Whatever you do you'll have to use a library like this (GD or libmagick or so) so that's unavoidable. With my system at least you totally skip the overhead of checking the cache, thus further reducing PHP interaction. You can implement this on your existing server, so I guess it's a solution well suited for your budget.

这篇关于通过即时调整大小服务图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆