nuxt / nuxt/image

Feature request: Aspect ratio

Open
#1,817 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.5k
Forks
331
Avg merge
19h 52m
Merged PRs (30d)
9

Description

Some providers, like Storyblok, automatically crop their images if width and height is supplied. E.g. if my image is 600x600 and I set width="600" height="300" it will automatically crop the image. This even works with focus points and facial regonition.

Unfortunately it is currently not possible to do so for multiple screen sizes with the use of sizes prop. It kinda works by setting the following:

<NuxtImg
      sizes="200px md:300px lg:600px"
      width="2"
      height="1"
      fit="crop"

This would render on mobile 200x100 and on desktop 600x300, BUT the img width and height props are still set to 2 and 1.

Possible solutions::

  • Define an aspect ratio with a new ratio prop: <NuxtImg sizes="200px md:300px lg:600px" :ratio="2/1" fit="crop" />
  • OR allow sizes to accept heights as well, e.g.: <NuxtImg sizes="200x100px md:300x150 lg:600x300" fit="crop" />

Further there is this issue #1466 requesting different aspect rations depending on the current screen size. If sizes allows for height it would support this, too. Otherwise, when adding ratio prop, also a ratios prop could be added to accept multiple ratios:

  • <NuxtImg sizes="200px md:300px lg:600px" ratios="2/1 md:3/2 lg:1" fit="crop" />

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how NuxtImg handles the sizes, width, height, and fit props. Compare the proposed ratio and height-aware sizes APIs with the related responsive-ratio request in issue #1466; done means responsive cropped images expose matching dimensions at each breakpoint through a chosen, documented API.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.