Next/Image - Limit Fill to no more than max width/height of original image #48429
jrobsontull
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Goals
Next/Image
infill
mode deliver no more pixels than maximum dimensions of the original imageOR:
Next/Image
Background
Currently,
Next/Image
when set tofill={true}
fills its parent container, no matter the dimensions of the original image. This results in low resolution images being larger than their original dimensions. UsingNext/Image
with specific width and height is a way to overcome this but this prevents the images from being as dynamic with relation to their size.Because we do not know the image dimensions of
fill={true}
images ahead of time, this makes maintaining aspect ratio sometimes troubling, as seen by the numerous stack overflow posts: 1, 2, 3, 4 (some examples).One implementation that sometimes works depending on the device is making use of
naturalWidth
andnaturalHeight
:Proposal
If the original dimensions of the image were exposed within
onLoadingComplete
, amax-width
and/ormax-height
could be set with styling. This would prevent the image from becoming larger than its original size.An alternative approach would be to limit the size of image served by
Next/Image
when its fill mode is set totrue
. I imagine that to generate differently sized images,Next/Image
must know the original dimensions of the image so this could be used to limit the maximum image size available.This would solve a huge range of styling problems associated with
Next/Image
, an incredibly useful tool for optimising web performance.Beta Was this translation helpful? Give feedback.
All reactions