[Fixed]-Django easy-thumbnails vs sorl-thumbnail differences


I hope this may help you
in the model, there are two fields image and thumbnail, in view make validation image type and size after that generate thumbnail using Pill

from PIL import Image as Img
from io import BytesIO

def create(self,request):
    mutable = request.POST._mutable
    request.POST._mutable = True

    for value in request.FILES.items():
        im = Img.open(value[1])
        im.thumbnail((425, 236), Img.ANTIALIAS)
        buffer = BytesIO()
        im.save(fp=buffer, format='JPEG')

        requset.POST['thumbnail'] = ContentFile(buffer.getvalue(), thumnail_name)

     request.POST._mutable = mutable

to save images in folder and thumbnails anther folder you can use different path with upload_to in ImageField



I’m not sure if this is helpful, but I’ve used easy-thumbnails in the past and I’m fairly sure that it does all of the things that you’re asking for if you configure it a bit. Configuring it with the save function is a bit tricky, as the save function doesn’t care to be configured, but it’s not impossible. The main thing that can cause problems is that you have to use ‘save and continue editing’ to access and use the thumbnail option. It won’t be visible until you do so if you haven’t created it already since it’s created on save.

def save()
    found_id = self.id
        super(Team, self).save(*args, **kwargs)
        if self.image and found_id is None and self.original_image_width and self.original_image_height:
            self.image = get_thumbnailer(self.image).get_thumbnail({
                'size': (self.original_image_width, self.original_image_height)
        super(Team, self).save(*args, **kwargs)

Leave a comment