image icon indicating copy to clipboard operation
image copied to clipboard

Feat: Add srcset property to nuxt-img and nuxt-picture

Open dannyalder88 opened this issue 3 years ago • 9 comments

As suggested in #216 the current implementation has poor support for handling different device pixel densities. This adds the srcset prop as suggested by ArtCraft so you can control which image sizes are created. It supports a string of widths in pixels to overwrite the images generated by the sizes prop or pixel density descriptors to adjust which images the sizes prop generates.

dannyalder88 avatar Apr 23 '21 09:04 dannyalder88

Hi @dannyalder88 Thanks for PR (and fixing typos). If you have a chance to check my comment https://github.com/nuxt/image/issues/216#issuecomment-840740583, if goal is supporting densities, I think it might be much easier for both users and maintenance to keep it as simple with sizes property (to be supported in nuxt-img as well). (until then adding pending label to distinguish PR status)

pi0 avatar May 13 '21 18:05 pi0

Finally got around to implementing the changes discussed in #216 (sorry it took a while been a busy month).

The latest changes change the srcset prop to a densities prop that only accepts single-digit density descriptions (1x 2x etc.). I've also added a global densities option that can be set in nuxt.config to make it easier to have all images produce the user's preferred densities.

I've noticed there's a lot more typescript being used throughout the project now. I'm not that familiar with it so if I've done anything wrong let me know and I can get it changed.

dannyalder88 avatar Jun 10 '21 20:06 dannyalder88

Is it correctly understood that this will enable e.g. retina images?

which will output images with: width = 500 and height = 200 if devices pixel density is 1x and width = 1000 and height = 400 if pixel density is 2x

madsh93 avatar Jul 23 '21 15:07 madsh93

Yes, it would generate retina sizes. It uses the size prop to create the files. So it will take what nuxt/image calculates as a size and then will use the density prop to generate the additional image sizes for retina. So if the sizes passed were "sm:100, md:400" this would generate images of 100, 200, 400 and 800 pixels wide. It adds these sizes to the generated code to let the browser know they are available and select the best image for the displayed width and pixel density.

dannyalder88 avatar Jul 23 '21 16:07 dannyalder88

Hey @dannyalder88 , is there anything blocking this PR? I would really need this feature to start using nuxt/ image in our project.

nikolashaag avatar Oct 22 '21 19:10 nikolashaag

Is there any progress on this? I'd love to get this on my blog to better handle retina screens

tetz2442 avatar Nov 15 '21 18:11 tetz2442

Hi! What is left to fix so that you can merge?

adinvadim avatar Dec 24 '21 11:12 adinvadim

Hey! Sorry, I've been absent on this. This is the first PR I've done for a package so I'm not 100% sure about the process of getting it merged/approved. I was just under the assumption it had been decided not to merge the feature for now as a package maintainer has to do it.

If there is still anything outstanding that I need to do my side let me know and I'll get it sorted.

EDIT: There is a newer PR here #459 which looks like it's doing the same thing automatically without the need for providing arguments. Might be a better fit now.

dannyalder88 avatar Dec 24 '21 12:12 dannyalder88

@pi0 has this been superseded by #459 and can be closed?

itpropro avatar Jun 25 '22 15:06 itpropro