Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果宽度超过“0”,则调整原始源的大小;x";值(django+;简易缩略图)_Python_Django_Image Size_Easy Thumbnails - Fatal编程技术网

Python 如果宽度超过“0”,则调整原始源的大小;x";值(django+;简易缩略图)

Python 如果宽度超过“0”,则调整原始源的大小;x";值(django+;简易缩略图),python,django,image-size,easy-thumbnails,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):

当尺寸大于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()
非常感谢

你考虑过吗

models.py

from django_resized import ResizedImageField

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