You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We would like to render images with a maximum width and/or height, and set the width and height attributes on the resulting <img> tag. An easier example would be this:
Image asset with id: image-38704787082d878c983f9327082be0033ae295bb-698x1056-png
We would like to render that image at a width of 200px, but we don't know the exact height of the image. So we end up with an <img src="..." width="200" /> and without a height set.
Another example would be using the same image, and requesting a w=200&h=150. The resulting image has a width of 99 and a height of 150, but we would be wrong to generate an element like this:
We could of course parse the asset ID to find the original image size, and/or use the image metadata to calculate this, but that does not feel scalable as any crop options might apply. All of the logic we would need for that is already being done in the urlForImage() function.
Describe the solution you'd like
We would like a spec method (or equivalent) on imageBuilder to retrieve the calculated specifications that contains the calculated width, height and/or aspect ratio, if it was possible to calculate it.
Describe alternatives you've considered
Duplicating the logic in imageBuilder to calculate the same
Parsing the resulting URL for information
Additional context
For proper page load performance it is important to set width and height explicitly on <img> elements.
The text was updated successfully, but these errors were encountered:
We would like to render images with a maximum width and/or height, and set the width and height attributes on the resulting
<img>
tag. An easier example would be this:Image asset with id:
image-38704787082d878c983f9327082be0033ae295bb-698x1056-png
We would like to render that image at a width of 200px, but we don't know the exact height of the image. So we end up with an
<img src="..." width="200" />
and without a height set.Another example would be using the same image, and requesting a
w=200&h=150
. The resulting image has a width of 99 and a height of 150, but we would be wrong to generate an element like this:We could of course parse the asset ID to find the original image size, and/or use the image metadata to calculate this, but that does not feel scalable as any crop options might apply. All of the logic we would need for that is already being done in the
urlForImage()
function.Describe the solution you'd like
We would like a
spec
method (or equivalent) onimageBuilder
to retrieve the calculated specifications that contains the calculated width, height and/or aspect ratio, if it was possible to calculate it.Describe alternatives you've considered
Additional context
For proper page load performance it is important to set width and height explicitly on
<img>
elements.The text was updated successfully, but these errors were encountered: