On this page
Add responsive images
Resize images and serve responsive sources.
Use Frontbacked image resizing when a theme needs smaller, cropped, or format-optimized versions of uploaded images. The browser still receives a normal image URL, but the URL points to a resized Frontbacked image.
Image resizing only works for Frontbacked-owned images, such as post upload file fields, site assets, logos, and theme assets. External image URLs are not transformed. When a source is external or invalid, the helper returns an empty string and logs a warning in development.
Basic Resize
Frontbacked.image.resize(source, options) accepts either a URL string or a file metadata object returned from Frontbacked uploads.
Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →
Use it in an attribute binding through a small wrapper function:
Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →
FQL function calls pass the resolved value into the registered function. In the example above, $.image.resizeProductThumb() passes the current list item's image value to resizeProductThumb.
Responsive Images
Use Frontbacked.image.srcset(source, entries) when the browser should choose the best width for the viewport.
Reference excerpt: use this with the page, variables and functions described in this guide. Try a complete example →
Each srcset entry uses the same options as resize. Entries with a w value are emitted as width descriptors, such as 640w.
Options
At least one of w/width or h/height is required.
| Option | Values | Purpose |
|---|---|---|
w or width | 16 to 2400 | Target width in CSS pixels. |
h or height | 16 to 2400 | Target height in CSS pixels. |
fit | scale-down, cover, crop, contain, pad, squeeze | Controls how the image fits the requested box. Defaults to scale-down. |
f or format | auto, webp, avif, jpeg, png | Output format. Use auto for normal theme images. |
q or quality | 40 to 90 | Output quality. Defaults to 82. |
dpr | 1 to 2 | Device pixel ratio multiplier for sharper images on dense screens. |
g or gravity | auto, center, top, bottom, left, right, top-left, top-right, bottom-left, bottom-right, face | Crop focus for cover and crop. |
bg or background | #ffffff or a simple color name | Background color for fit: "pad". |
enlarge | true or false | Allows upscaling. Defaults to false. |
Continue with Prepare images for your layout.