Capítulo 367 de 456
next/legacy/image is the pre-v13 Image component, kept only for backward compatibility. Deprecated since v16.0.0; use next/image instead.
next/legacy/image: renamed from the old next/image in v13; wraps <img> in a <span> and uses layout/objectFit/objectPosition props instead of style/className.layout: one of intrinsic (default), fixed, responsive, fill — controls resize behavior and generated srcSet/sizes.loader: function ({ src, width, quality }) => url to resolve image URLs, overrides the next.config.js loader.unoptimized: serves the source as-is, skipping quality/size/format transforms.remotePatterns / domains: next.config.js allowlist for external image hosts; domains is deprecated in favor of remotePatterns.import Image from 'next/legacy/image'
const myLoader = ({ src, width, quality }) => {
return `https://example.com/${src}?w=${width}&q=${quality || 75}`
}
const MyImage = (props) => (
<Image loader={myLoader} src="me.png" alt="Picture of the author" width={500} height={500} />
)
loader prop resolving the final image URL.layout | Behavior | srcSet | sizes |
|---|---|---|---|
intrinsic (default) | scale down to fit container, up to image size | 1x,2x | N/A |
fixed | exact width/height | 1x,2x | N/A |
responsive | scale to fit container width | width-based | 100vw |
fill | grow to fill parent (needs position: relative on parent) | width-based | 100vw |
next/legacy/image: deprecated, will be removed; use next/image.unoptimized/dangerouslyAllowSVG: blocked by default for security.layout="fill" requires the parent to have position: relative.remotePatterns (or the deprecated domains) configuration.unoptimized bypasses the whole optimization pipeline, useful for tiny/animated/vector images.next/image is the direct, non-legacy replacement.deviceSizes, imageSizes, formats, minimumCacheTTL all apply to the legacy loader too.