I
I
IIITRIX2019-06-13 20:42:46
Django
IIITRIX, 2019-06-13 20:42:46

How to resize on the fly?

Tell me how to resize an image on the fly!
for example
, we have a field in the user model

picture = models.ImageField(_('Аватар'), upload_to=avatar_upload_to, null=True, blank=True)

when you click on the link
http://localhost:8000 /m/users/avatar.jpg
, the avatar uploaded by the user opens
How to make it so that when you go to
http://localhost:8000 /m/users/crop/30x30/avatar.jpg

The image was resized without saving.
If we substitute any value instead of 30, it will immediately change the resize, respectively, no higher than the original size!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2019-06-14
@IIITRIX

I agree that the server should not deal with the client's problems; the client should send an image with the required dimensions, and the server will simply check it and answer "yes" or "no".
Prepare on the client side via JS ( https://fengyuanchen.github.io/cropperjs/ ) or just specify the parameters.

I
Ivan Yakushenko, 2019-06-13
@kshnkvn

It seems to me that this should be done in the HTML itself.
The following suggestion is 100% wrong, but most likely working: in the /m/users/crop/30x30/ route, return a copy of the same page that is rendered when going to /m/users/, only for the img tag specify additional attributes width and height. In general, it's more correct to just pass these attributes to django itself so as not to duplicate the page, but I don't know how to do it ¯\_(ツ)_/¯

S
sim3x, 2019-06-13
@sim3x

https://djangopackages.org/grids/g/thumbnails/
https://www.google.com.ua/search?q=nginx+resize+im...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question