Skip to content

v1.12.0

Choose a tag to compare

@euoia euoia released this 30 Oct 11:54
· 15 commits to main since this release

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. CmsImage applies it as object-position on the <img>, merged after any style the 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, width and height following 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) and images: { crop: true } in astroadmin.config.js, which shows the crop control. A build with a crop stored and no crop-capable service fails naming the image; in astro dev the crop is skipped, the <img> marked data-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.json entries 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; null clears) 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 when images.crop is set without the service, the service without images.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/config once 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.