Open hartmut-co-uk opened 2 years ago
As for a solution on how to extend <nuxt-img>
- how about adding 2x
(3x?
, ..?) props?
<nuxt-img
src="/cat.png"
alt="(5) <nuxt-img> with sizes defined for 1x size & and prop `2x` to also have double pixel density srcset generated"
class="w-full"
width="1200"
height="630"
2x
sizes="sm:250px lg:500px"/>
Alternatives ideas
density2x
(, density3
, ...?)pixel-device-ratio="1 2 3"
densities="1x 2x 3x"
Would you consider support for this to be added, any preference on which props to go for?
How about adding following boolean props? Or would that make it too restricted? Though I think this should solve most use cases?
'2x': { type: Boolean, default: undefined },
'3x': { type: Boolean, default: undefined },
'4x': { type: Boolean, default: undefined },
like for preload
https://github.com/nuxt/image/blob/db0934c1afb124c579c7c272c0f8c103e360baf5/src/runtime/components/_base.ts#L21
Can I go ahead and create a PR? https://github.com/nuxt/image/pull/459/files by @SimonBackx seemed mostly complete, but was abandoned?
Astro uses widths
in addition to sizes
to explicitly define image variants to be provided.
I think this would also be a good + straight option?!?
ref: https://docs.astro.build/en/guides/integrations-guide/image/#widths
This is a very common issue, and as suggested in the comments above a PR was already created by @simonBackx Why is this not a priority to fix?
Thanks for diving into this @hartmut-co-uk, I really hope this will give the extra push it needs.
Astro uses
widths
in addition tosizes
to explicitly define image variants to be provided. I think this would also be a good + straight option?!? ref: docs.astro.build/en/guides/integrations-guide/image/#widths
This is a good solution, the current sizes
prop:
Even better would be giving the option to globally define transform widths in the module config, and the srcset
of every <NuxtImg>
would contain the same transforms (see nuxt-responsive-loader
).
Generating specific transform URLs based on the expected widths of every unique image element across an app makes no sense, and defeats the point of srcset
:
<img>
using the sizes
attributesrcset
, while also taking into account devicePixelRatio
On the second part I don't agree. Requirements can be very different, the render/display size. E.g. an avatar/profile picture vs. images you might render in full width of your main section and/or are able to enlarge / view in fullscreen.
Of course, sizes
attribute serves as a hint to modern browsers only.
But when e.g. preloading via link
(<head>
), the responsive instructions via sizes
still hold value to the browser's decision which variant to preload, based on window size and DPR.
Yeah that is fair, would be good to have the option for both, quick and easy global transforms or more granular, separate controls for transforms and display sizes.
This would be extremely valuable to us as well. Subscribing to notifications. Thanks for all the work!
。。。
img.png img@2x.png img_h5.png img_h5@2x.png md:h5 lg:pc
I've got a similar issue with DPI 2x, where I've got a full width image that is always 500px height. On mobile width 320px DPI 2x a 640x500 image is being selected by the browser from the srcset. This is an issue since the image aspect ratio is wrong. The DPI 1x image is 320x500 and the DPI 2x image needs to be 640x1000 rather than 640x500.
Example NuxtPicture usage for fixed height 100% width
<NuxtPicture src="/cat.png" :height="500" fit="cover"></NuxtPicture>
Output
<picture>
<source type="image/webp" sizes="(max-width: 320px) 320px, (max-width: 640px) 640px, (max-width: 768px) 768px, (max-width: 1024px) 1024px, (max-width: 1280px) 1280px, (max-width: 1536px) 1536px, 1536px" srcset="/_ipx/f_webp&fit_cover&s_320x500/cat.png 320w, /_ipx/f_webp&fit_cover&s_640x500/cat.png 640w, /_ipx/f_webp&fit_cover&s_768x500/cat.png 768w, /_ipx/f_webp&fit_cover&s_1024x500/cat.png 1024w, /_ipx/f_webp&fit_cover&s_1280x500/cat.png 1280w, /_ipx/f_webp&fit_cover&s_1536x500/cat.png 1536w, /_ipx/f_webp&fit_cover&s_1536x500/cat.png 1536w">
<img height="500" data-nuxt-pic="" src="/_ipx/f_jpeg&fit_cover&s_1536x500/cat.png" sizes="(max-width: 320px) 320px, (max-width: 640px) 640px, (max-width: 768px) 768px, (max-width: 1024px) 1024px, (max-width: 1280px) 1280px, (max-width: 1536px) 1536px, 1536px" srcset="/_ipx/f_jpeg&fit_cover&s_320x500/cat.png 320w, /_ipx/f_jpeg&fit_cover&s_640x500/cat.png 640w, /_ipx/f_jpeg&fit_cover&s_768x500/cat.png 768w, /_ipx/f_jpeg&fit_cover&s_1024x500/cat.png 1024w, /_ipx/f_jpeg&fit_cover&s_1280x500/cat.png 1280w, /_ipx/f_jpeg&fit_cover&s_1536x500/cat.png 1536w, /_ipx/f_jpeg&fit_cover&s_1536x500/cat.png 1536w">
</picture>
I am a little confused, the live docs have chapters called densities:
But it looks to me like using the density settings are not yet working - and obviously, this issue is still open as well as this PR https://github.com/nuxt/image/pull/227/files
So I assume, densities have not yet been implemented?
Thanks!
Hi everyone, with https://github.com/nuxt/image/pull/769 a first step has been implemented - just as the docs say.
I think the docs reflect the main branch until 1.0.0
GA is reached.
So densities
can be used with latest @nuxt/image-edge
.
Note: Please don't consider the API stabilised until next RC/GA. Discussions are still ongoing - that's why I've kept the issue open.
Feature Request
Support (nuxt3) nuxt/image with vercel provider for static app ->
nuxt generate
.Example Repo
https://github.com/hartmut-co-uk/nuxt3-image-pixel-device-ratio-2x-support
Context
Source: https://medium.com/@woutervanderzee/responsive-images-with-srcset-and-sizes-fc434845e948
Demo
Hosted on vercel: https://nuxt3-image-pixel-device-ratio-2x-support.vercel.app/
PageSpeed Insights
Lighthouse Scan: https://pagespeed.web.dev/report?url=https%3A%2F%2Fnuxt3-image-pixel-device-ratio-2x-support.vercel.app%2F&form_factor=desktop
Conclusion
I'd like nuxt/image to somehow allow
srcset
to be created which includes pixel-device-ratio 2x (maybe others, too?) such as the manually coded option (4) which includes srcset options for [250w, 500w, 1000w].This is the only solution which provides both
on all devices.
Rendered as
⚠️ Note: I'm actually not quite sure if the
sizes
is correct or if it's going to be ignored by the browser anyway - cause the browser chooses from srcset for the best choice consideringpixel-device-ratio
?!? ...happy to be put right by someone with more insight!