Re:Issues with Cloudflare Images
by gregbrimble on Tuesday December 07, 2021 @12:58PM
(#29475899)
I think "scale-down" is the closest to what you're after. If you have a 400x600 original, and request 512x512, you'll be served a 341x512 image. This maintains the original image's aspect ratio, and a fits within the requested (512x512) size.
Original: https://via.placeholder.com/400x600 Resized: https://gregbrimble.com/cdn-cgi/image/fit=scale-down,w=512,h...
Re:Issues with Cloudflare Images
by LukeLambert on Tuesday December 07, 2021 @01:28PM
(#29476287)
I want to maintain the aspect ratio of my crop, not that of the source image. Perhaps `fit=cover-scale-down` would be a more appropriate name. In other words, I always want a square image <= 512px wide. I think this is a very common use case.
If there's no way to specify where the center (or w/e) of your crop is on the source image, it's not going to happen.
Even I can do ‘most interesting part’ detection. CF certainly can.
Re:Issues with Cloudflare Images
by user-the-name on Tuesday December 07, 2021 @12:56PM
(#29475873)
Isn't that fit=crop?
Re:Issues with Cloudflare Images
by LukeLambert on Tuesday December 07, 2021 @01:50PM
(#29476594)
fit=crop and fit=cover only work well if the source dimensions are greater than 512×512. If either dimension of the source is smaller, the behavior is useless.
fit=cover will return a square (as requested), but will enlarge it (which you never want because it wastes bandwidth).
fit=crop will cut off excess pixels if either dimension exceeds 512, but it does not always return a square. (And contrary to the docs, it does not behave like fit=scale-down.)
Edit: Changed suggested name of fit mode for clarity.