On-Demand thumbnail creation with django and nginx
Posted
by sharjeel
on Stack Overflow
See other posts from Stack Overflow
or by sharjeel
Published on 2010-05-25T07:36:18Z
Indexed on
2010/05/25
7:41 UTC
Read the original article
Hit count: 295
I want to generate thumbnails of images on the fly.
My site is built with django and deployed using nginx which serves all the static content and communicates with django/apache using reverse proxy.
Right now, for every image in my site, I generate all required sizes of thumbnails on-hand and deliver them when required. The problem is that whenever I change the size of a thumbnail, I have to regenerate all of them (and they are tons).
However now I'd like to generate the thumbnail the first time it is accessed and later on nginx would deliver the same file over n over. If I delete that thumbnail file because of lesser accesses, it should get generated automatically the next time. Thumbnails in my case also have watermarks which require some computation logic of my application so a webserver thumbnail module might not work very well.
The size of the thumbnail can be embedded in the URL. So http://www.example.com/thumbnail/abc_320x240.jpg gets the 320x240 size of the thumbnail.
The approach I'm looking right now is to let nginx lookup the file and if it doesn't exist, forward the query to my django application which would create the thumbnail and send either the response or a redirect string. However I'm not sure about the concurrency issues and any other issues which might pop up later.
What is the appropriate way to achieve this?
© Stack Overflow or respective owner