-
Notifications
You must be signed in to change notification settings - Fork 60
Description
In order to explain why I think the current SanityImage params are not flexible enough, I'm going to give an example.
Let's say I have a 400x400 div in my website that I want to fill with an image that comes from Sanity. If I was building the image url by hand, I'd use the following params: w=400&h=400&fit=min
. This always gives me a square image (perfect for my square div), shrinks large images as needed, and doesn't scale up small images (CSS can do that if needed).
Now, using a fluid query (and yes, I know that in this specific example I could use a fixed query, but I simplified for sake of brevity), all I can say is (maxwidth: 400, maxHeight: 400)
. If the image that I have in Sanity has more that 400 width and height, I get the same image as if using the params w=400&h=400&fit=min
, but if one size of the image is smaller, let's say 500x200, it results in these params w=400&h=200&fit=crop
, which gives me an image that is not square (and thus wastes bandwidth by fetching an image where half of it is never shown, and also results in a stretched image if seen on a browser that doesn't support object-fit).
What I'd like is to have more control over the final url, first by being able to set the fit
parameter (in my case, to min
), second by not having the lib changing the aspect ratio of the values I give it (if I give it a maxWidth and maxHeight of 400, the url shouldn't have a width of 400 and height of 200, independent of the size of the image being fetched).
I know there must be a million reasons for things to be the way they are that I'm not aware of, but the way they are now is also limiting, so I was hoping to start a discussion on how we could improve things.