如果宽度超过" x"则调整原始来源的大小。值(django + easy-thumbnailnails)

时间:2014-06-07 16:58:03

标签: python django image-size easy-thumbnails

当尺寸大于x值时,我尝试调整原始源(ThumbnailerImageField对象)的大小。一切都好,直到我必须做大小调整,我不知道如何完成。

这是我的代码:

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()

非常感谢!!!!

1 个答案:

答案 0 :(得分:0)

您是否考虑过

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')