--- import { Image } from 'astro:assets'; import corgi from '../assets/corgi.jpg'; import ContextAlert from '../components/ContextAlert.astro'; import Diff from '../components/Diff.astro'; import Markdown from '../components/Markdown.astro'; import Layout from '../layouts/Layout.astro'; import { getNetlifyContext } from '../utils'; const sampleImage = '/images/corgi.jpg'; const ctx = getNetlifyContext(); const forceWebP = ctx === 'dev'; const sampleImageSrcSet = [640, 1280, 2048] .map((size) => { return `/.netlify/images?url=${sampleImage}&w=${size}${forceWebP ? '&fm=webp' : ''} ${size}w`; }) .join(', '); const sizes = '(max-width: 1024px) 100vw, 1024px'; const astroImageSnippet = ` ## Using the built-in Astro <Image /> component Astro's \`Image\` component will automatically use Netlify Image CDN to serve optimized images. ~~~jsx --- import { Image } from 'astro:assets'; import corgi from '../assets/corgi.jpg'; --- // Later in your markup... Corgi ~~~ `; const originalVsCdnSnippet = ` ## Original vs. optimized image: can you tell the difference? In the code below, a regular \`\` tag is used in both cases for a framework-agnostic example. Note that aside from Astro's \`Image\` or rolling your own \`\` tags, you can also use the excellent [unpic-img](https://unpic.pics/) package. ~~~jsx // <== On the left, the original image Corgi // ==> On the right, explicitly using Netlify Image CDN endpoint for a responsive image Corgi ~~~ `; const devModeWarning = ` In local development, optimization is performed locally without automatic format detection, so format is set to WebP. `; ---
{ return ctx === 'dev' ? devModeWarning : null; }} class="mb-8" />

Image CDN

Corgi
Credit: photo by Alvan Nee on Unsplash
Corgi
Corgi