({
src,
sizes,
unoptimized = false,
priority = false,
loading,
lazyRoot = null,
lazyBoundary,
className,
quality,
width,
height,
style,
objectFit,
objectPosition,
onLoadingComplete,
placeholder = 'empty',
blurDataURL,
...all
}: ImageProps)
| 674 | * @deprecated The `next/legacy/image` component is deprecated and will be removed in a future version of Next.js. Please use `next/image` instead. |
| 675 | */ |
| 676 | export default function Image({ |
| 677 | src, |
| 678 | sizes, |
| 679 | unoptimized = false, |
| 680 | priority = false, |
| 681 | loading, |
| 682 | lazyRoot = null, |
| 683 | lazyBoundary, |
| 684 | className, |
| 685 | quality, |
| 686 | width, |
| 687 | height, |
| 688 | style, |
| 689 | objectFit, |
| 690 | objectPosition, |
| 691 | onLoadingComplete, |
| 692 | placeholder = 'empty', |
| 693 | blurDataURL, |
| 694 | ...all |
| 695 | }: ImageProps) { |
| 696 | const configContext = useContext(ImageConfigContext) |
| 697 | const config: ImageConfig = useMemo(() => { |
| 698 | const c = configEnv || configContext || imageConfigDefault |
| 699 | const allSizes = [...c.deviceSizes, ...c.imageSizes].sort((a, b) => a - b) |
| 700 | const deviceSizes = c.deviceSizes.sort((a, b) => a - b) |
| 701 | const qualities = c.qualities?.sort((a, b) => a - b) |
| 702 | return { |
| 703 | ...c, |
| 704 | allSizes, |
| 705 | deviceSizes, |
| 706 | qualities, // During the SSR, configEnv (__NEXT_IMAGE_OPTS) does not include |
| 707 | // security sensitive configs like `localPatterns`, which is needed |
| 708 | // during the server render to ensure it's validated. Therefore use |
| 709 | // configContext, which holds the config from the server for validation. |
| 710 | localPatterns: |
| 711 | typeof window === 'undefined' |
| 712 | ? configContext?.localPatterns |
| 713 | : c.localPatterns, |
| 714 | } |
| 715 | }, [configContext]) |
| 716 | |
| 717 | let rest: Partial<ImageProps> = all |
| 718 | let layout: NonNullable<LayoutValue> = sizes ? 'responsive' : 'intrinsic' |
| 719 | if ('layout' in rest) { |
| 720 | // Override default layout if the user specified one: |
| 721 | if (rest.layout) layout = rest.layout |
| 722 | |
| 723 | // Remove property so it's not spread on <img>: |
| 724 | delete rest.layout |
| 725 | } |
| 726 | |
| 727 | let loader: ImageLoaderWithConfig = defaultImageLoader |
| 728 | if ('loader' in rest) { |
| 729 | if (rest.loader) { |
| 730 | const customImageLoader = rest.loader |
| 731 | loader = (obj) => { |
| 732 | const { config: _, ...opts } = obj |
| 733 | // The config object is internal only so we must |
nothing calls this directly
no test coverage detected