Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create a thumbnail in a view, rather than dynamically via a template? #744

Open
typonaut opened this issue Aug 22, 2023 · 0 comments

Comments

@typonaut
Copy link

typonaut commented Aug 22, 2023

I am uploading images, and rather than create thumbnails dynamically via a template tag, I want to create the necessary thumbnails when the upload is done. This should essentially mirror what the template tag would do. So where:

{% thumbnail object.user.address.address_img "240" crop="center" as im %}
		<img itemprop="image" 
				src="{{ im.url }}" 
				alt="{{ object.display_name }}" 
				title="{{ object.display_name }}"
				width="{{ im.width }}"
				height="{{ im.height }}" 
				class="page-img"/>
									
{% endthumbnail %}

I would like to leave that code on the template, but pre-generate the thumbnail in the view:

th_img = get_thumbnail(object.user.address.address_img, '240', crop='center')

th_img has properties key, name, url, etc, but no file is created in the cache, and there is no entry in the thumbnail_kvstore.

How do I "save" the thumbnail and get an entry in the thumbnail_kvstore?

The thumbnail cannot go into a field for the model, because there are other sizes of thumbnail to be generated too.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant