3 ms·
Image Resizing is technically a separate product, so I apologize if this is off-topic, but it appears to be missing the most useful `fit` mode – something like
by LukeLambert 5y ago
Image Resizing is technically a separate product, so I apologize if this is off-topic, but it appears to be missing the most useful `fit` mode – something like `fit=cover-scale-down`. I never want to enlarge an image on the server, since I can do that client-side. If I request a version with the dimensions 512×512 (square), but the source image is only 400×600, there should be a way to get a resulting image of 400×400. Am I misreading the docs?
https://developers.cloudflare.com/images/image-resizing/url-format https://developers.cloudflare.com/images/image-resizing/url-...
Edit: Changed suggested name of fit mode for clarity.
- user-the-name 5y agoIsn't that fit=crop?
- deleted 5y ago[deleted]
- LukeLambert 5y agofit=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.)
- gregbrimble 5y agoI 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 https://via.placeholder.com/400x600 Resized: https://gregbrimble.com/cdn-cgi/image/fit=scale-down,w=512,h=512/https://via.placeholder.com/400x600 https://gregbrimble.com/cdn-cgi/image/fit=scale-down,w=512,h...
- LukeLambert 5y agoI 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.