Skip to content

[next/image] Responsive images with "art direction" #19880

Closed Answered by leerob
jasonsilberman asked this question in Help
Discussion options

You must be logged in to vote

Update: We have extracted the core logic from next/image into a new unstable_getImgProps() function.

This allows usage outside of <Image>, such as:

  1. Working with background-image or image-set
  2. Working with canvas context.drawImage() or simply new Image()
  3. Working with <picture> media queries to implement Art Direction or Light/Dark Mode images

Example

import { unstable_getImgProps as getImgProps } from 'next/image'

export default function Page() {
  const common = { alt: 'Hero', width: 800, height: 400 }
  const { props: { srcSet: dark } } = getImgProps({ ...common, src: '/dark.png' })
  const { props: { srcSet: light, ...rest } } = getImgProps({ ...common, src: '/light.png' })

  return (<

Replies: 7 comments 32 replies

Comment options

You must be logged in to vote
7 replies
@dfellows12
Comment options

@aNyMoRe0505
Comment options

@thexpand
Comment options

@rein96
Comment options

@bobaaaaa
Comment options

Comment options

You must be logged in to vote
3 replies
@aghoneim92
Comment options

@aghoneim92
Comment options

@gkpty
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
8 replies
@ncorso
Comment options

@AdrianFahrbach
Comment options

@drMonro
Comment options

@MartinaMilisic
Comment options

@bobaaaaa
Comment options

Comment options

You must be logged in to vote
6 replies
@bobaaaaa
Comment options

@AlexandreBourdeaudhui
Comment options

@coelhucas
Comment options

@NickWoodward
Comment options

@revnelson
Comment options

Answer selected by leerob
Comment options

You must be logged in to vote
2 replies
@ddaoxuan
Comment options

@cvbuelow
Comment options

Comment options

You must be logged in to vote
6 replies
@revnelson
Comment options

@Emanuele-Fortunati
Comment options

@revnelson
Comment options

@Arunjenson
Comment options

@revnelson
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet