Responsive images
A responsive image lists several variants of the same image in a srcset, and lets the browser download the one that fits the screen. Picasso writes that list for you. The only thing it cannot guess is how wide the image is displayed in your layout: that is the sizes prop.
Two kinds of images
Section titled “Two kinds of images”The image width depends on the viewport (full-width banner, column of a grid…). Give sizes, and the srcset lists every width of device_sizes and image_sizes, up to the source width:
<twig:Picasso:Image src="photo.jpg" width="800" height="600" sizes="(max-width: 768px) 100vw, 800px" alt="…" />srcset="…?w=16… 16w, …?w=32… 32w, … , …?w=1920… 1920w"The image is always displayed at the same size (avatar, logo, thumbnail). Leave sizes out: the srcset holds the 1x and 2x (retina) variants of width:
<twig:Picasso:Image src="photo.jpg" width="320" height="240" alt="…" /><picture> <source type="image/avif" srcset="/image/glide/filesystem/kittens.jpg?w=320&h=240&fm=avif&q=75&fit=contain&s=678e6d483c1c8b660d5d23f3ee3a7ba8 1x, /image/glide/filesystem/kittens.jpg?w=640&h=480&fm=avif&q=75&fit=contain&s=b3df2806a0f53e0b2becd6e5e8538fb6 2x" /> <source type="image/webp" srcset="/image/glide/filesystem/kittens.jpg?w=320&h=240&fm=webp&q=75&fit=contain&s=01c37ff1f41b385f56fa73e2bb1dcd3e 1x, /image/glide/filesystem/kittens.jpg?w=640&h=480&fm=webp&q=75&fit=contain&s=350e1be8c3471a08a77ffd36b2d72f0d 2x" /> <img src="/image/glide/filesystem/kittens.jpg?w=320&h=240&fm=jpg&q=75&fit=contain&s=2da5bda893475172456c51f8982ed770" srcset="/image/glide/filesystem/kittens.jpg?w=320&h=240&fm=jpg&q=75&fit=contain&s=2da5bda893475172456c51f8982ed770 1x, /image/glide/filesystem/kittens.jpg?w=640&h=480&fm=jpg&q=75&fit=contain&s=f0a099238f172669fec4416461baf36d 2x" width="320" height="240" loading="lazy" alt="Three tabby kittens" /></picture>What the browser picks
Section titled “What the browser picks”sizes tells the browser how many CSS pixels the image takes, the screen density turns them into device pixels, and the browser takes the first variant at least that wide. With sizes="(max-width: 768px) 100vw, 800px":



Writing sizes:
- Describe the layout, not the image:
(max-width: 768px) 100vw, 800pxreads “full width on small screens, 800 CSS pixels otherwise”. - The first matching condition wins: list the narrow screens first.
- An approximation is fine. Too large wastes bytes, too small blurs the image.
- In a grid of three columns:
(max-width: 768px) 100vw, 33vw.
Formats
Section titled “Formats”Each format of formats but the last becomes a <source>, tried in order, and the last one is the <img> fallback. The default [avif, webp, jpg] serves AVIF to browsers that support it, WebP to the others, and JPEG to the rest.
Every format multiplies the variants of each image: 16 widths × 3 formats is 48 renders for a crawler fetching them all. Trimming the widths your layout never uses, or dropping WebP when you serve AVIF, cuts the cost of a cold cache.
Avoiding layout shifts
Section titled “Avoiding layout shifts”The browser reserves the space of an image from its width and height attributes, before it loads. Picasso only writes them when it knows both:
- give both, or
- give one, and let Picasso read the other from the source: this needs metadata resolution, on by default for filesystem loaders.
