github timnarr/kirby-imagex 0.4.0

latest release: 0.4.1
4 hours ago

Added

  • New focus snippet option (default false). Applies Kirby's native focus content field (the same one thumb(['crop' => true]) already uses for cropping) as object-position on the <img>, plus object-fit: cover. Falls back to 'center' when no focus point is set. New resolveFocusValue() helper, backed by a new isValidCssPositionValue() validator: since focus is Panel-editable content rather than developer-controlled input, its value is validated against the shape object-position actually accepts before being embedded in generated CSS, falling back to 'center' on anything else — closing a CSS/HTML-injection path into the <style> tag described below.
  • New Imagex::getArtDirectionStyles() method. artDirection sources only ever control which thumbnail the browser picks — the rendered <img> keeps the base ratio/focus point regardless of which source matched. This method returns @media-scoped !important CSS (targeting the <img>'s id, auto-generated unless one is set via attributes.img) for every artDirection entry whose ratio or (with focus enabled) image actually differs from the default, so the <img> stays visually in sync with the active source. The imagex-picture snippet renders this automatically in a <style> tag; imagex-picture-json exposes it as the artDirectionStyles key. Result is memoized per instance. The id lookup checks the active loading mode before falling back to shared, matching getImgAttributes()'s own resolution order.
  • New tests/bootstrap.php, wired up via phpunit.xml's bootstrap attribute. Sets Kirby\Cms\App::$enableWhoops = false — needed now that resolveFocusValue() is tested against a real Kirby\Cms\File, which lazily bootstraps a default App instance for blueprint resolution and would otherwise register Whoops as a global error/exception handler for the rest of the test run.

Fixed

  • Bug: compareFormats could serve a larger, non-optimal format when 3+ formats were configured (e.g. formats: ['avif', 'webp'] combined with addOriginalFormatAsSource: true). The format-skip logic only skipped the format immediately preceding the smallest one, not every format before it, so browsers could still pick a larger format listed earlier. Fixed by extracting the (already-correct) skip logic used for art-directed sources into a shared isFormatSkippable() helper, now used by both the default and art-directed source paths.
  • Imagex constructor now validates ratio, srcset, and compareFormats the same way it already validates image and loading, throwing a descriptive InvalidArgumentException instead of a generic TypeError when instantiated directly with missing/invalid options.

Changed

  • srcHandler() now accepts an optional $customLazyloading override parameter instead of always re-reading the timnarr.imagex.customLazyloading config option; Imagex passes its already-cached value.

Full Changelog: 0.3.0...0.4.0

Don't miss a new kirby-imagex release

NewReleases is sending notifications on new releases.