How to use sorl-thumbnail without django?

Go To


In my case I have an opportunity to generate image thumbnails and do some post-processing before they are uploaded to a server (Amazon S3) on administrators computer.
I know that sorl checks if thumbnail exists before generating it, but utilize kinda complicated naming scheme, so I hope there is a way to access sorl directly from my script.

Official documentation says nothing about using sorl-thumbnail standalone, any suggestions?

2012-04-03 20:03
by Andrew
A client side python script? Could you elaborate on that as I think there might be some confusion between client and serve - Timmy O'Mahony 2012-04-03 20:14
@Timmy, by client-side I mean administrators physical PC. I know that it may seem strange not to do post-processing on server, but it simplifies things a lot in this particular case - Andrew 2012-04-03 20:18
Ok, so you want to run a stand alone python script client side to upload to a server - I thought you meant browser client sid - Timmy O'Mahony 2012-04-03 20:21
I want to run standalone python script on client-side to generate thumbnail images, they would be uploaded later (manually or by separate script). I know that if thumbs would be named properly sorl can pick them up even if they aren't listed in DB - Andrew 2012-04-03 20:24


I'd recommend you look at the source for sorl-thumbnail. Really all sorl-thumbnail is, is a wrapper around PIL (python imaging library). Although I'm sure you can figure out a way possibly to uncouple sorl-thumbnail from django it's going to be nontrivial. That said if you say set it up as a management command (with the full django environment as a result), you'd be able to use the low level api as documented in the sorl-thumbnail docs.

That said you probably will be better off just figuring out how sorl-thumbnail interfaces with PIL and reproducing that part of the code in a decoupled manner since you will have to do additional post processing (likely with PIL again) that sorl-thumbnail can't do anyway.

Also bear in mind on all of this, I'm not sure what your intention is...none of this is something you could set up to be run on off of a webserver. You can't run a python script on a client's computer who is connecting to a django server, that's just beyond impossible. However, generating a python program to produce watermarked thumbnails is completely possible if you're just handing it out to some coworkers or something.

If you indeed are trying to have arbitrary people visit your site and upload watermarked/thumbnailed files to you via a web interface...well then you'll want to start some serious javascript studying.

2012-04-03 22:55
by John
Thanks, I would try to figure out how file naming works in sorl then. By "client-side" I meant that administrator has script and run it on his computer, not in his browser. I edit the question, so no one else gets confused - Andrew 2012-04-03 23:39


Unless you're doing something complex, I would consider using ImageMagick for this kind of offline processing. For simple tasks like scaling an image and compositing a logo, it's quicker and easier to write an ImageMagick one-liner:

convert in.jpg -scale 200x200 logo.png -gravity SouthEast -composite out.jpg

than to implement the same thing in PIL.

2012-04-03 23:04
by Gareth Rees
Thanks. I do know how to resize images, the real problem is how sorl name files, so I hoped to utilize sorl directly, without digging into code - Andrew 2012-04-03 23:27