Field type
image
Media library image picker. Stores a full image object — URL, alt, dimensions, focal point, zoom, and the settings the block asks for. Two uses, two sets of settings: a BACKGROUND behind a block (the defaults: cover / contain / tile, width, repeat, fixed) or a PICTURE drawn as an <img> (enableShape: true, enableTile: false, enableRepeatOptions: false, enableFixedBackground: false: a Shape instead of Size). For a picture a person places on its own among other blocks, use the Picture block (gcb/picture) instead of writing a field.
Type: image · Stored attribute type: object
Stored value
object — { url, alt, width, height, id, focalPoint?: {x, y} 0–1, zoom?: number, size?: cover|contain|auto, customWidth?, repeat?, isFixed?, ratio?: ""|4/5|1/1|4/3|16/9 }
Supports
- Media library picker with full image metadata
- Optional FocalPointPicker for cover-cropping
- Optional cover / contain / tile size selectors with custom width
- Optional background-repeat and fixed-background toggles
- Optional Shape (aspect ratio) for a picture drawn as an
<img>
Config options
| Option | Type | Default | Description |
|---|---|---|---|
enableFocalPoint | boolean | true | Show the FocalPointPicker so the author can choose a focus point for cover-cropping. |
enableSizeOptions | boolean | true | Show cover / contain / tile + custom-width selectors. |
enableTile | boolean | true | The Tile option and the custom width. Turn off for a picture drawn as an <img>, which cannot be tiled. |
enableShape | boolean | false | A Shape of its own (ratio: empty for its own, or 4/5, 1/1, 4/3, 16/9), for a picture that stands in the page as an <img>. The shape is the fit, so Size is not offered: its own shape shows the whole picture (and can be zoomed out to half, zoom 0.5–3), any other is covered, cropped round the focal point (zoom 1–3). The block chooses the set: a background image keeps the defaults; an <img> turns this on and Tile, repeat and fixed off. |
enableRepeatOptions | boolean | true | Toggle for background-repeat (active when size !== "cover"). |
enableFixedBackground | boolean | true | Toggle for background-attachment: fixed. |
Gotchas
- A picture is never taller than the screen: nobody scrolls a picture. The Picture block holds itself to 88% of the screen's height (a shaped picture is cut shorter round its focal point; a picture in its own shape is made narrower). When you draw an
<img>yourself, hold it the same way (max-height: 88svhwithobject-fit: cover). - With
enableShapethere is no cover / contain choice: the shape is the fit.ratioempty = the whole picture at its own shape; any otherratio=object-fit: coverin that shape. Do not readsizefor such a picture. - Tile, custom width, repeat and fixed are background-only: they do nothing on an
<img>, so turn them off there. - Optional fields only appear when the corresponding
enable*flag is on AND the author touched the control. Always destructure with defaults in React.
Example
{ "id": "ctrl_cover",
"type": "image",
"label": "Cover image",
"attributeKey": "cover",
"validation": { "required": true },
"parentPanelId": "panel" }Background or picture: which settings
The field is used two ways, and the block says which by the settings it asks for.
| Background behind a block | Picture drawn as an <img> | |
|---|---|---|
| Ask for | nothing (the defaults) | "enableShape": true, "enableTile": false, "enableRepeatOptions": false, "enableFixedBackground": false |
| Focal point | yes → background-position | yes → object-position |
| Zoom | yes, 1–3 (when it covers) | yes, 1–3; from 0.5 at its own shape |
| Size: Cover / Contain / Tile | yes → background-size | no — the Shape is the fit |
| Custom width, Repeat, Fixed | yes | no — an <img> cannot do them |
Shape (ratio) | no — the block is the shape | yes: empty = its own shape, whole picture; 4/5, 1/1, 4/3, 16/9 = covered, cropped round the focal point |
Image field or Picture block
- An image field when the picture is part of a block you are writing — a card's photo, a team member's portrait, a
hero's background. Your
render.phpdraws it; the person edits it in that block's sidebar. - The Picture block (
gcb/picture) when the picture is a thing on its own that a person places among other blocks — in a Layout box, beside words. It is this field with the picture settings, already drawn; there is nothing to write. Round corners are set on the box it sits in, not on the picture.
Consume
JSX
export default function Hero({ attributes }) {
const cover = attributes.cover;
if (!cover?.url) return null;
return (
<div
className="hero"
style={{
backgroundImage: `url(${cover.url})`,
backgroundSize: cover.size || 'cover',
backgroundPosition: cover.focalPoint
? `${cover.focalPoint.x * 100}% ${cover.focalPoint.y * 100}%`
: 'center',
}}
/>
);
}PHP
<?php
$cover = $attributes['cover'] ?? null;
if (!$cover || empty($cover['url'])) return;
$bg_pos = isset($cover['focalPoint'])
? sprintf('%d%% %d%%', $cover['focalPoint']['x'] * 100, $cover['focalPoint']['y'] * 100)
: 'center';
?>
<div
class="hero"
style="background-image:url(<?php echo esc_url($cover['url']); ?>);
background-size:<?php echo esc_attr($cover['size'] ?? 'cover'); ?>;
background-position:<?php echo esc_attr($bg_pos); ?>;"
></div>Consume as a picture (<img>)
With "enableShape": true, "enableTile": false, "enableRepeatOptions": false, "enableFixedBackground": false:
<?php
$pic = $attributes['photo'] ?? null;
if (!$pic || empty($pic['url'])) return;
$ratio = in_array($pic['ratio'] ?? '', ['4/5', '1/1', '4/3', '16/9'], true) ? $pic['ratio'] : ''; // '' = its own shape
$at = isset($pic['focalPoint'])
? sprintf('%d%% %d%%', $pic['focalPoint']['x'] * 100, $pic['focalPoint']['y'] * 100)
: '50% 50%';
$zoom = max($ratio === '' ? 0.5 : 1, min(3, (float) ($pic['zoom'] ?? 1)));
?>
<figure style="margin:0;overflow:hidden;<?php echo $ratio !== '' ? 'aspect-ratio:' . esc_attr($ratio) . ';' : ''; ?>">
<img
src="<?php echo esc_url($pic['url']); ?>"
alt="<?php echo esc_attr($pic['alt'] ?? ''); ?>"
style="display:block;width:100%;height:<?php echo $ratio !== '' ? '100%' : 'auto'; ?>;object-fit:cover;
object-position:<?php echo esc_attr($at); ?>;
transform:scale(<?php echo esc_attr($zoom); ?>);transform-origin:<?php echo esc_attr($at); ?>;"
/>
</figure>Every field also takes the keys common to all fields.