On-Demand thumbnail creation with django and nginx
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 thumb开发者_StackOverflow社区nail 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?
What you are describing is how sorl.thumbnail works minus the watermarking. But you could probably modify sorl pretty easily to add your watermarking to the basic thumbnailing that it does.
精彩评论