New image resizing mode `shrink_fit`

Hi!

I recently started using zola and found myself using shortcodes for automatic image downscaling.
After trying around a little bit, I found that using any fit mode always resizes the image to the exact specified size of the respective dimension.
Since I only want to optimize my website for mobile usage, the upscaling of images was rather troubling than helpful, since the quality of automatically upscaled image was naturally poorer and looked really bad.

Because of this I thought that a new mode might be useful (shrink_fit), which only resizes and fits to the specified dimensions, if the image is bigger than the specified sizes in any dimension.

I already applied the changes in my fork and I’m ready to open a PR, if you like the idea:

Otherwise feel free to criticize the idea or to suggest changes.

Best regards,
Arne

Hello!

That looks like a good addition but I’m wondering if fit should do that directly rather than adding a new mode. If an image is already fitting, there shouldn’t be anything done to it with fit I think?

That would most likely be the easiest way to implement this, but it would prevent users to scale images up. I’m not sure if anybody needs the upscaling functionality, but that’s for you to decide :slight_smile:

I really don’t think many people actually want upscaling, except maybe for SVGs which aren’t supported (yet). I could be wrong though. Can you open the PR replacing the behaviour of fit and I’ll ping the original author to see if he has some thoughts?