Michael
Michael

Reputation: 4461

ResizeToFit(width=max(source_pic_width, 750)

django-imagekit==4.0

I have organized something like this:

class Image(CommonUrlMethodsMixin, GeneralModel):

    pic = models.ImageField(verbose_name=_("Image"), upload_to=get_upload_path)
    pic_xs = ImageSpecField(source='pic',
                                 processors=[ResizeToFit(width=500)],
                                 format='JPEG',
                                 options={'quality': 60},
                                 autoconvert=True)
    pic_sm = ImageSpecField(source='pic',
                                 processors=[ResizeToFit(width=750)],
                                 format='JPEG',
                                 options={'quality': 60})
    pic_md = ImageSpecField(source='pic',
                                 processors=[ResizeToFit(width=970)],
                                 format='JPEG',
                                 options={'quality': 60})
    pic_lg = ImageSpecField(source='pic',
                                 processors=[ResizeToFit(width=1170)],
                                 format='JPEG',
                                 options={'quality': 60})

The problem is that a user can upload a small picture. Like 800 px wide. In this case there seems to be is no reason to stretch it to 970 and 1170. Let it be just original 800.

In this case I would prefer something like ResizeToFit(width=max(self.pic.width, 750). But I have failed to do that.

Could you explain this matter to me?

Upvotes: 1

Views: 1451

Answers (1)

kostans3k
kostans3k

Reputation: 467

ResizeToFiTaccepts another parameter called upscale. By default is True, but when set to False, image will not be enlarged if its dimensions are smaller than the target dimensions.

processors=[ResizeToFit(width=970, upscale=False)]

Upvotes: 2

Related Questions