easy-thumbnails icon indicating copy to clipboard operation
easy-thumbnails copied to clipboard

Do not generate thumbnail for image smaller than alias sizes

Open Akiat opened this issue 5 years ago • 4 comments

Hi and thank you for this great module.

Is there a way to not generate a new thumbnail when the alias size is greater than the original image size ?

e.g with these aliases:

THUMBNAIL_ALIASES = {
    'web_app': {
        'small': {'size': (150, 150), 'crop': True},
        'medium': {'size': (500, 1000), 'crop': False},
        'big': {'size': (1000, 2000), 'crop': False},
    },
}

If I upload an image with a size of 300x300, it will be great to only have 1 thumbnail generated (the small one), and the other which redirect on the original image when we access it via thumbnail_url(self.media_field, 'medium').

If it's not yet supported, do you think it can be a feasable upgrade ?

Thanks !

Akiat avatar Nov 01 '20 22:11 Akiat

For each thumbnail to be created, easy-thumbnails first generates a unique name using the given parameters (size, crop, upscale, etc.). It then checks if an image with that name already exists. If so, that image is used, otherwise it is generated.

There is a function which generates that name. You can override it and add your own logic. Then for instance you can generate the same name for medium and big images.

I hope this helps.

jrief avatar Nov 01 '20 22:11 jrief

Thanks for your quick reply 👍

Do you have the name of this function ?

Akiat avatar Nov 01 '20 23:11 Akiat

https://easy-thumbnails.readthedocs.io/en/latest/ref/settings/?highlight=namer#easy_thumbnails.conf.Settings.THUMBNAIL_NAMER

jrief avatar Nov 02 '20 05:11 jrief

Thanks a lot, I tried to re-use the logic of the namer "alias", but thumbnail_options.get('ALIAS', '') returns nothing.

https://github.com/SmileyChris/easy-thumbnails/blob/master/easy_thumbnails/namers.py#L30

How can I access the name of the requested alias ?

Akiat avatar Nov 02 '20 10:11 Akiat