M
M
Maxim Zubenko2018-12-06 10:47:48
Django
Maxim Zubenko, 2018-12-06 10:47:48

Is it possible to use easy thumbnails in Django to shrink images as soon as they are added?

Good health everyone!
So I'm using Django 2
Installed a battery easy thumbnails
It works just fine as a thumbnail creator. And he does his job.
But, I came across the fact that client managers do not understand that it is necessary to reduce the file and add pictures to the server by 8-12 mb. Explanations don't help.
The question is whether this battery (because it is already in use) can be used just for the purpose that when a file is added (exactly at the moment when it was added to the server), its size decreased and the file (the main one, from which they will then make other pedestals) was recorded immediately in a reduced size.
Sincerely!
ps because in English I'm not very good, then in the full documentationimplementation of just such a task for Django was not found
by ps2. Do not offer a solution with JS before sending

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Zubenko, 2018-12-06
@JawsIk

Basically, I found the solution myself. The method of collecting the whole from pieces of documentation.
So if in steps.
1. Installation
2. In the model, we connect and describe the image field in a similar way as below:

from easy_thumbnails.fields import ThumbnailerImageField

class Category(models.Model):
    name = models.CharField(max_length=100)
    slug = models.SlugField(blank=True, max_length=100)
    # image = models.ImageField(default='img/my-default.gif') # а так было
    image = ThumbnailerImageField(default='img/my-default.gif', 
                                  resize_source=dict(quality=95, 
                                                     size=(2048, 2048), 
                                  sharpen=True))

3. Making migrations. And it works.
Works on the principle of "b on the other side". Those. if the picture is 10000x5000 , then it will become 2048x1024 and vice versa, if the second parameter was initially larger, then it will also be larger in the final image.

S
Sergey Nizhny Novgorod, 2018-12-06
@Terras

An image file comes from the form.
You process it with any native python one to compress the image .
You save the source
. Then you throw the source into easy thumbnails for crop.
Ps Do not offer a solution with JS before sending - tears from easy thumbnails to js and a native python library (I mark the photos by dots).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question