Serving Images with on-the-fly resize

前端 未结 8 610
生来不讨喜
生来不讨喜 2021-01-30 03:48

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

We have several websites (adult entertainment) that display images like dvd cov

8条回答
  •  难免孤独
    2021-01-30 03:51

    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.

    It works like this:

    • 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

    EDIT: 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.

提交回复
热议问题