Skip to content

Take DPI into account when requesting fixed size images #644

Description

@kara

To reproduce:

  1. Add nuxt/image to modules (in config, yarn add, etc)
  2. Add nuxt/image instance with width and height set
<nuxt-img src="cat.jpg" width="300" height="200" />

Expected behavior:
Image component has a srcset attribute that defines a different image width for 1x and 2x images. On a laptop with 2x DPI, the image should ultimately be requested at 600px (2x DPI x given width).

Expected result:

<img src="cat.jpg" srcset="cat.jpg?w=300 1x, cat.jpg?w=600 2x" />

Actual behavior:
There is no srcset attribute generated. On a laptop with 2x DPI, the image is requested at 300px instead of 600px. As a result, the image produced looks grainy.

Actual result:

<img src="cat.jpg?w=300&h=200" />

Suggested change:
The image component should take the user's DPI into account when requesting images by defining a srcset with density descriptors. Given that mobile devices can have unnecessarily high DPI (e.g. 3x), it may be optimal to cap the DPI at 2x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions