Answer the question
In order to leave comments, you need to log in
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)
http://localhost:8000 /m/users/avatar.jpg
http://localhost:8000 /m/users/crop/30x30/avatar.jpg
Answer the question
In order to leave comments, you need to log in
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.
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 ¯\_(ツ)_/¯
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question