Responsive Image APIs: Choose Formats, Sizes, and Fallbacks

Choose responsive image sizes, formats, and crops from the needs of your actual interface. Learn how browser candidates, transformation recipes, derivative generation, and repeatable visual checks fit into a practical photo delivery policy.

By PhotosAPI.com · Photos API Lab

RIGHT FORMAT — RIGHT SIZE: neon typography with a multicolor pinstripe frame and PhotosAPI.com branding.

A responsive image API should deliver a photograph that suits the space where it appears, the quality the task requires, and the formats the client can use. Those are separate decisions. Converting every original into a fashionable format will not fix an oversized download, an awkward crop, or an image that moves the page while loading.

Build your delivery policy around actual screens and representative photographs. This guide describes an illustrative architecture for a content application with article cards, a large feature image, and a detailed photo viewer. The photograph edit API guide covers transformation requirements, while the photos API overview puts delivery in the wider asset lifecycle.

Start with the places images appear

Inventory each image component before generating derivatives. Record its aspect ratio, typical rendered width, maximum useful size, and whether a user can inspect fine detail. A small author portrait, a wide landscape banner, and an equipment photograph with readable labels have different quality requirements even when all three are photographs.

Give each component an output profile that frontend and processing code can share. For an article card, the profile might define a landscape crop and several width candidates. For the detail viewer, it might preserve the source composition and allow a larger output. Keep the names connected to product roles so the reason for a derivative remains understandable months later.

Review the inventory when the layout changes. A design update that turns a three-column grid into a single wide feature can invalidate assumptions about the images being delivered.

Understand the browser contract

The WHATWG HTML image standard defines width candidates through srcset and describes sizes as the intended layout width used in source selection. The browser chooses among candidates using that information and factors such as pixel density. A picture element can offer alternative formats through typed source elements or alternate compositions through media conditions. The img element supplies a fallback. Width and height information also lets the browser allocate space before the image arrives.

The following markup is illustrative and uses fictional local image paths. Its layout assumption is a card that spans nearly the viewport on narrow screens and occupies a 360-pixel slot on wider screens. Match the sizes expression to your component’s CSS before adapting it.

<picture>
  <source type="image/webp"
    srcset="/media/card-480.webp 480w, /media/card-960.webp 960w"
    sizes="(max-width: 600px) calc(100vw - 32px), 360px">
  <img src="/media/card-480.jpg"
    srcset="/media/card-480.jpg 480w, /media/card-960.jpg 960w"
    sizes="(max-width: 600px) calc(100vw - 32px), 360px"
    width="960" height="640"
    alt="A footpath winding between coastal cliffs">
</picture>

Choose width candidates deliberately

A useful candidate set covers common display needs without creating a separate output for every possible width. Start from the component inventory, then examine the gap between neighboring candidates. If a component regularly needs an intermediate size, compare the transferred bytes and visual result before adding another derivative.

For example, a team could evaluate 480, 960, and 1440 pixels as an initial set for its article imagery. Those numbers are a starting experiment, not a standard recommendation. A narrow thumbnail system may need much smaller outputs; a detailed photograph viewer may need a larger ceiling. Measure the actual workload instead of inheriting a width list from an unrelated website.

Decide what happens when an original is smaller than the requested output. Returning its available resolution, disallowing enlargement, or applying an explicitly chosen enlargement process are different product policies. Document the behavior so the frontend does not promise detail that the source never contained.

Evaluate formats using your photographs

Treat JPEG, WebP, AVIF, and other supported candidates as options to measure in your delivery environment. Compare the actual encoded output at the intended display size. Include processing time, transfer size, visual quality, and behavior in your required clients. Avoid adopting a universal percentage-saving claim as a capacity estimate for your own collection.

Create a small evaluation set that reflects the content you publish. Include fine foliage, smooth skies, skin tones, dark scenes, sharp text within photographs, and images with transparency if your product accepts them. A setting that works well for a landscape may damage the legibility of a photographed label. Record those differences as part of the acceptance decision.

Keep the comparison fair. Use the same source, crop, output dimensions, and color treatment for each candidate. Do not compare a smaller, more aggressively compressed output with a larger reference and attribute the entire difference to the format. Choose a fallback you have verified across the clients your product supports.

Separate crop decisions from resolution decisions

Resolution changes can preserve the same composition. A different crop changes what the viewer sees. Treat the latter as an editorial choice with its own review process. A person’s face, the product being sold, or the subject of an article should not disappear because the mobile card happens to use a different ratio.

Store a focal point or an approved crop where your product needs that control. Preview the result in every component that uses it. For a documentary or inspection workflow, consider whether a crop should be labeled and whether the uncropped image remains accessible. What looks attractive in a feed may omit information that a user needs to make a decision.

When an image carries meaningful embedded text, check the narrowest presentation first. If the words cannot remain readable, create a different composition or put the information into ordinary page text.

Version the complete transformation recipe

Identify a derivative by its source version and the choices that determine its pixels: crop, dimensions, orientation handling, color treatment, encoding settings, and processing version. A recipe identifier makes those dependencies concrete. If you change one of them, decide whether to publish a new derivative identity rather than silently replacing an established output.

This helps explain differences during debugging. Two images with the same width can look different because they were processed with different crops or encoder settings. Store enough information to reproduce the published result when investigating a report. The photo filter and color pipeline guide expands on keeping color operations consistent between preview and final output.

For shared delivery caches, review which request inputs distinguish one output from another. Make sure your routing and cache configuration preserve those distinctions, including format choices and any access boundary.

Decide when derivatives should be generated

Generating every possible variant during upload simplifies later delivery but can spend work on photographs that nobody views. Generating everything on demand avoids that initial expansion but introduces work into the first view. Choose the tradeoff by profile rather than applying one rule to the entire system.

For the illustrative content application, precomputing the common article-card image might be reasonable because the publishing flow always needs it. A rarely used detailed output could follow a different policy. Coalesce duplicate requests for the same unfinished derivative so a sudden burst does not schedule identical work repeatedly.

Include derivative retention in the decision. If a recipe becomes obsolete, determine when its outputs can be removed and how the system will respond if an old page still references them. The photo API cost model helps connect these choices to storage and processing budgets.

Measure the experience, not only the file

A smaller file is useful only when the delivered experience improves. Test a complete page on representative devices and connection conditions. Inspect which image was actually requested, whether its dimensions fit the component, whether the subject remains clear, and whether the layout stays stable as images arrive.

Evaluate the first visible image separately from photographs further down the page. Decide which assets are critical to understanding the screen and which can wait until they are needed. Avoid applying one loading rule everywhere without observing the effect on the initial view and subsequent scrolling.

Keep a comparison record for meaningful changes: the input set, recipe versions, page layout, client conditions, transferred bytes, and visible defects. This turns optimization into a repeatable decision instead of a sequence of settings that nobody can explain.

Conclusion: make delivery a shared policy

A dependable responsive image system combines component-aware sizes, measured format choices, intentional crops, and reproducible derivatives. Begin with a small set of outputs and expand it when evidence shows a real need. Capture the agreed profiles and client assumptions in your integration planning documentation. That shared contract keeps frontend layout, image processing, and delivery costs aligned as the product grows.

Photo Processing · Photos API Lab← Back to all articles