Resizing the original source if width exceeds "x" value (django + easy-thumbnails)

316 views Asked by At

i am tryng to resize the original source (ThumbnailerImageField object) when dimensions are bigger than x value. It is all ok until i have to do the resize that i dont have any idea how to accomplish.

This is my code:

def save(self):
    if self.pk is None:
        self.original_name = self.image.name[:50]

        if (self.image.width > 800 or self.image.height > 800):
            ratio = float(self.image.width) / float(self.image.height)
            if ratio > 1:
                target_size=(800, int(800/ratio))
            else:
                target_size=(int(800*ratio),800)

            HOW IS THE SINTAXIS HERE ??
            self.image.how_to_resize_original(target_size) ????????????????????

     super(ImageUpload, self).save()

Thanks a lot !!!!

1

There are 1 answers

0
mishbah On

Have you considered

https://github.com/un1t/django-resized

models.py

from django_resized import ResizedImageField

class MyModel(models.Model):
    ...
    image = ResizedImageField(max_width=500, max_height=300, upload_to='whatever')