Sorl thumbnail has a low-level API that allows you to do, for example:
from sorl.thumbnail import get_thumbnail
im = get_thumbnail(my_file, '100x100', crop='center', quality=99)
This returns a reference to the cached file. If it's already been created, it's super quick. However, if it has to create it for the first time it can take a long time when using remote storage such as S3.
Is there a way to run a command in Python (ie. not in a template) to check if sorl will have to generate a thumbnail for the first time?
PS. I'm aware of similar question here but this is asking about it in a template context, and has a hacky solution as an answer that uses custom SQL and not the sorl API.
In my version
sorl.thumbnail
,11.12
, the methodget_thumbnail
is defined in sorl.thumbnail.base.py and starts as follows:If you use this code and return something like
this should give you the desired result.