One cover for different screens: cropping and responsive delivery
Three crop families, six unchanged WebP files and six actual browser conditions: currentSrc, bytes, CSS geometry and raster-quality limits.
A wide cover shows a lighthouse, the sea and a small sailboat. In a square card, the lighthouse is the main subject we need from that scene. Taking the central portion can leave the sea while cutting off the roof. Delivering the large original everywhere means that a successful crop alone will not make the file smaller.
The exercise has one original geometric illustration and three crop families. Source geometry and files were checked separately, followed by exactly six browser conditions. Actual currentSrc, response bytes and CSS geometry confirm delivery of the intended family. The experiment does not establish raster rendering quality.
First decide what must stay in the frame
Our source is an SVG with a 1600 × 1200 canvas. The lighthouse occupies the rectangle from (820, 280) to (1060, 840). That covers the entire structure, from the roof to the bottom step. The sun, boat and edges of the shore add context but are outside the essential area.
This rectangle is more useful than a single “focal point”. Keeping a point inside the future crop does not guarantee that the roof and base will remain visible. We will freeze the boundaries before creating derivatives, then inspect the images themselves: geometry cannot judge the strength of a composition.
| Presentation | Source rectangle: x, y, width, height | Prepared dimensions |
|---|---|---|
| Portrait cover | 480, 0, 960, 1200 | 480 × 600; 960 × 1200 |
| Wide cover | 0, 150, 1600, 900 | 800 × 450; 1600 × 900 |
| Square card | 620, 240, 640, 640 | 320 × 320; 640 × 640 |
All three rectangles contain the essential area. The card leaves little space above the roof and below the steps; the wide cover shows the surroundings; the portrait crop retains the path. These are deliberate editorial decisions for this illustration. A group portrait or a diagram would need different boundaries and criteria.
Each crop has its own family of sizes
The 480 × 600 and 960 × 1200 pair represents one portrait composition. The files differ in raster dimensions. The wide and square compositions have their own pairs. The six files therefore do not form one shared list of interchangeable candidates.
We use picture to select a composition and srcset within it to select a size. The HTML Standard describes these tasks as art direction and resource selection according to presentation conditions. Our example keeps them as separate decisions: first the required crop, then a candidate from that crop.
A name such as portrait-480.webp makes the example easy to read, but the full recipe contains more: the source image, rectangle, output dimensions, format and encoding parameters. If an editor moves the crop, the old address must not silently identify a different immutable result. In a production pipeline, this connects to derivative versions and cache rules.
We do not enlarge raster crops during preparation. The largest square has the same 640 × 640 pixels as its area in the source raster. The smaller file is a reduction of that same crop. This makes it straightforward to check that changing candidates does not change the editorial choice.
Let the markup follow the layout width
The exercise container is at most 960 CSS pixels wide, with horizontal gutters totalling 32 pixels. Up to and including a viewport width of 600 pixels, we choose the portrait crop. On wider screens the cover becomes horizontal. The composition breakpoint and the container’s maximum-width breakpoint are different.
Both families use the same hint:
sizes="(min-width: 992px) 960px, calc(100vw - 32px)"
The container’s CSS accordingly uses width: calc(100vw - 32px) and max-width: 960px; the image fills its width. A 390-pixel viewport gives us 358 pixels, an 800-pixel viewport gives 768, and a 1440-pixel viewport gives 960. The sizes attribute itself does not set the element’s width: the layout does that.
The portrait source has media="(max-width: 600px)" and 480w, 960w candidates; the remaining markup offers the wide 800w, 1600w pair. A width descriptor must match the actual file, as the img reference states. Calling a file 960w while leaving only 480 pixels inside gives the browser incorrect information.
Under the chosen conditions, the card has a fixed width of 320 CSS pixels, sizes="320px" and its own square candidates. It does not inherit the large cover’s dimensions merely because it uses the same subject.
The portrait source declares width="960" height="1200"; the wide img declares 1600 and 900. The source dimension attributes communicate the selected composition’s proportions. This helps reserve space before the image appears; the absence of layout shifts still needs to be checked on the page.
Screen density does not promise an exact choice
For a 358 CSS-pixel slot at DPR 2, the arithmetic reference is 716 raster pixels. We offer 480 and 960. This explains why the larger candidate exists, but does not make its selection a universal guarantee. The browser has discretion, including consideration of its own conditions and policies.
The largest screen in our set introduces another tradeoff. A 960-pixel slot at DPR 2 would need 1920 pixels for a two-to-one ratio, while the largest wide file has 1600. Its ratio to the slot is approximately 1.67. The prepared set deliberately has no 1920-pixel candidate.
In that situation, we can reconsider the display width, prepare a more detailed source, or accept the limitation after assessing the appearance. Enlarging an existing raster alone cannot recover lost detail. We leave that limitation visible in the protocol, so a dense display receives no unsupported promise of quality.
Nor should we check selection only by repeatedly narrowing one open window. Earlier downloads create different conditions. Every navigation in the prepared matrix will have a new context; resizing an already open page remains a separate scenario.
Separate file bytes from delivery
The six WebP files have already been created from the original SVG. Inkscape rendered the source; ImageMagick handled cropping, reduction and encoding. Every derivative uses quality 82 and WebP method 6. The figures below are the resulting local file sizes, without network conclusions.
| Family | Smaller file, bytes | Larger file, bytes |
|---|---|---|
| Portrait | 6192 | 13 348 |
| Wide | 7582 | 17 546 |
| Card | 3140 | 6408 |
These numbers depend on this particular geometric scene and encoding. They do not predict the size of a photograph containing foliage or small lettering. Comparing the portrait and wide families as an identical scene with different “efficiency” would also be misleading: their areas and contents differ.
The executed run records received body length, encodedBodySize and transferSize separately. Resource Timing defines these fields, but transferSize is neither exact packet capture nor a separate measurement of HTTP headers.
The example’s local server does not apply HTTP compression to WebP. We can therefore compare the received bytes with a particular file and check its body accounting. That is not yet an assessment of page speed, CDN costs or a mobile data bill.
Six conditions for checking delivery
Widths of 390, 800 and 1440 CSS px ran at DPR 1 and 2, each with height 900. Resources shared one local origin, no-store, disabled CDP cache and a fresh context per case. No CPU/network throttling was added; this set does not measure speed or LCP.
Each case retained currentSrc, family, manifest raster dimensions, actual CSS rectangle, already received response-body bytes/hash, raw Resource Timing, DOM and computed styles. Received bytes and encodedBodySize matched the unchanged six WebP files; visual quality was not assessed.
We will record naturalWidth separately. As MDN defines it, this is a density-corrected width in CSS pixels. It cannot automatically be equated with the downloaded WebP’s raster width. File geometry and element geometry have separate fields.
Chromium 151.0.7922.34 with Playwright 1.60.0 passed all six conditions. At 390 px it selected portrait; at 800/1440 it selected landscape, while the card remained square. Hero rectangles were 358 × 447.5, 768 × 432 and 960 × 540 CSS px; the card was 320 × 320. DOM text stayed the same, and different DPR at the same width did not change rendered geometry/styles. This observes one browser rather than requiring every browser to select the same filename.
What remains outside the checks
All three source rectangles mathematically contain the lighthouse essential rectangle. That checks crop coordinates rather than proving readability of the smallest raster or sampling quality. At 960 CSS px, the largest landscape1600 remains a ceiling of approximately 1.67 raster pixels per CSS px at DPR 2.
The browser showed no horizontal page overflow. Actual End and Control+Home keys reached the footer and returned to the top; Tab was recorded separately, but the fixture has no interactive controls. This is not a usability study. Loading shifts, resizing an already open window, other browsers, widths outside the matrix and raster quality remain unverified.
The exact static fixture was added to one existing Demo without new dependencies, a Kernel or routes. A dedicated loopback HTTP server checked those files; Symfony/backend/CDN pipelines and production were not exercised. The result separates crop family, resource selection and actual bytes from assumptions about appearance and speed.