1

当尺寸大于 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()

非常感谢 !!!!

4

1 回答 1

0

你有没有考虑过

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

模型.py

from django_resized import ResizedImageField

class MyModel(models.Model):
    ...
    image = ResizedImageField(max_width=500, max_height=300, upload_to='whatever')
于 2014-06-08T01:27:20.717 回答