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?
ResizeToFiT
accepts 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)]