Repository navigation
v1.12.0
Image focal point and non-destructive crop (#82).
Features
- Focal point. In the image library, click a public upload's preview to mark the subject.
CmsImageapplies it asobject-positionon the<img>, merged after anystylethe site passes;focalPoint={false}opts a slot out. With no point the rendered HTML is unchanged. - Non-destructive crop. Drag a rectangle over the preview; the original file is kept and every AVIF/WebP/JPEG variant is cut from the crop, with
widths,widthandheightfollowing it and the focal point translated into the crop frame. Needs two opt-ins:image: { service: { entrypoint: 'astroadmin/image-service' } }in the Astro config (a wrapper of Astro's sharp service that extracts the crop before resizing; animated WebP and 16-bit sources survive) andimages: { crop: true }inastroadmin.config.js, which shows the crop control. A build with a crop stored and no crop-capable service fails naming the image; inastro devthe crop is skipped, the<img>markeddata-cms-image="crop-skipped"and the log warned. - Cropped previews. The image field's preview, the library grid and gallery thumbnails show a stored crop with a "Cropped" caption, updating as soon as a crop is saved or cleared.
- Image details keyed by site path.
public/images/.metadata.jsonentries are keyed by the image's site path (/images/x.jpg); entries an older admin keyed by bare filename are still read for files directly under/images/and moved on the next edit. The metadata routes validate what they store (alt a string, focal point and crop percentages inside the image;nullclears) and take the item's folder (?source=), so same-named files in different folders keep separate details. Deleting an image removes its details. - Doctor check
image-crop-service. Warns whenimages.cropis set without the service, the service withoutimages.crop, or a stored crop on a site without the service; a service named by another spelling is reported as unconfirmed rather than failing (the build checks the loaded service).
Fixes
- The image library listed only one of two same-named files across folders; the image() folder's file is now listed beside the upload.
- An unchanged alt save no longer rewrites
.metadata.json; a cleared field never leaves an empty entry. - The dashboard reads
/api/configonce per page load (ui/admin-config.js).
Tests
New: image-metadata, image-focal-browser, image-crop-preview-browser, image-service (all in npm test), plus additions to cms-image-packed (focal point, crop byte-compared with the site's sharp, the crop-skipped dev run) and doctor-images. Three review rounds; every fix seen red first.
Known: the publish response's commit summary can undercount deletions on every other commit (simple-git 4.0.2, #102); the commits themselves are correct.