简体   繁体   中英

How to use sorl-thumbnail without django?

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM