Image Thumbnail Proxy

A friend of mine asked me how to check if a file exists remotely (http 404) so that he can create thumbnail for images which don’t have a thumbnail of that size.

As what he planned to do, a visitor browse his page, his script will check all images ready for rendering have a suitable thumbnail.

Checking a HTTP 404 is quite easy, but it’s not wise checking on page’s loading, if there are n images to be checked, a single page visit would makes server requests n to 2*n times for checking/generating thumbnail. These requests are useless at most time.

Another way doing this is sending a request on 404.
Read nginx’s documentation for error_page, it gives a example:

This is what I’m about to do.

I’ve push nginx conf and php code to github:
Thumbnail is generated using imagemagick convert, the geometry I use is ‘widthxheight‘, there are more here.

Original url should be like:
And the thumbnail like:

Image Thumbnail Proxy by @sskaje: