Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not generate thumbnail for image smaller than alias sizes #558

Open
Akiat opened this issue Nov 1, 2020 · 4 comments
Open

Do not generate thumbnail for image smaller than alias sizes #558

Akiat opened this issue Nov 1, 2020 · 4 comments

Comments

@Akiat
Copy link

Akiat commented Nov 1, 2020

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 Akiat changed the title Do not generate thumbnail for image with width and height smaller than alias sizes Do not generate thumbnail for image smaller than alias sizes Nov 1, 2020
@jrief
Copy link
Collaborator

jrief commented Nov 1, 2020

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.

@Akiat
Copy link
Author

Akiat commented Nov 1, 2020

Thanks for your quick reply 👍

Do you have the name of this function ?

@Akiat
Copy link
Author

Akiat commented Nov 2, 2020

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants