question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Responsive image sizing

See original GitHub issue

We live in a time when websites should work on a huge range of devices with different sizes and densities, it is not enough to have only one version of image… at least 2 versions of each file (1x and 2x) is a must for modern web, but in many cases it may be reasonable to have 3-4 sizes of each file in webp format + fallback to jpg/png, so each picture usually may be resized/converted to 2-4-6 or more versions.

Problems:

  • There is no way do define image sizes for high density image versions
  • Presets do not allow to use sizes property available for nuxt-img
  • (for @nuxt/content) Images inside .md files that included using .md syntax are not processed by @nuxt/image, it would be very nice if it is possible to set a default sizing using preset for those images

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:6
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

26reactions
pi0commented, May 13, 2021

Hi @ArtCraft. Thanks for detailed proposal. Supporting densities, for sure makes sense. But I am thinking if main purpose is that, we can think about easier interface like this:

<nuxt-img sizes="sm:200px, md:500px" densities="1x 2x">

This way we can easily auto calculate all required additional densities and omit close variants. Also as you mentioned about preset, we can allow a global (nuxt.config) option to specify required densities and remove need of specify it on each use case.

What do you think about this?

6reactions
ArtCraftcommented, Apr 18, 2021

for example

<nuxt-img src="/picture1.jpg" sizes="sm:200px, md:500px"  alt="test"></nuxt-img>

this generates following code

<img
   srcset="/_ipx/pic1.jpg?w=200 200w, /_ipx/pic1.jpg?w=500 500w"
   sizes="(max-width: 640px) 200px, 500px"  
   src="/_ipx/pic1.jpg?w=500"    
   alt="test"
/>

on retina display (device pixel ratio 2.0) optimal image sizes would be 400px and 1000px, but srcset attribute do not provide those sizes

what should be generated to look good is:

<img
   srcset="/_ipx/pic1.jpg?w=200 200w, /_ipx/pic1.jpg?w=400 400w, /_ipx/pic1.jpg?w=500 500w, /_ipx/pic1.jpg?w=1000 1000w"
   sizes="(max-width: 640px) 200px, 500px"
   src="/_ipx/pic1.jpg?w=1000" 
   alt="test"
/>

so there should be some way to define those sizes as well something like

<nuxt-img 
    srcset="200w, 400w, 500w, 1000w" 
    sizes="sm:200px, md:500px" 
    src="/picture1.jpg" 
    alt="test"
></nuxt-img>

almost like img tag but with skipped filenames in srcset which going to be filled in automatically

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Create Responsive Images - W3Schools
Responsive images will automatically adjust to fit the size of the screen. Resize the browser window to see the responsive effect:.
Read more >
CSS Responsive Image Tutorial: How to Make Images ...
Making an image fluid, or responsive, is actually pretty simple. When you upload an image to your website, it has a default width...
Read more >
Responsive images - Learn web development | MDN
In this article, we'll learn about the concept of responsive images — images that work well on devices with widely differing screen sizes, ......
Read more >
Responsive images - web.dev
Sizing hints # ... If you know the dimensions of the image you should include width and height attributes. Even if the image...
Read more >
Responsive Images Done Right: A Guide To <picture> And ...
The sizes attribute tells the browser how many pixels it needs by describing the final rendered width of our image. Think of sizes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found