Nginx, Timthumb and Cache

Sometimes our applications uses different image sizes for movie posters and grids in general that are not supported by the clients API.

This is a solution that allow you to generate thumbnails and cache them.
Timthumb is an opensource solution to resize images, and it works very good, but it has a problem, Timthumb cache is not that good and stores image cache inside a text file, and it requires to execute the timthumb script everytime the user is requesting for an image.

So, this is a modified version of timthumb script, to save the generated thumbnails in a physical location as an image, not as a txt file.

And everytime when a user request for a thumbnail, it goes to the Nginx controller to check if the file / image already exists in the physical location, much more faster than doing a request to the timthumb PHP script, and only if the thumb have not been generated, nginx calls timthumb script to generate the cached thumbnail only once.

Plus, I use Amazon CloudFront as an extra cache level on the top.

Nginx config:
https://gist.github.com/farandal/5923317

TimThumb version:
https://github.com/farandal/timthumb

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s