Guide
Image
Render public image references in views with safe URLs, intrinsic dimensions, and presentation attributes.
Render an ImageReference in a view
ImageReference carries a safe public-relative path, the actual dimensions, and the image format. Pass it to $helpers->image() with ImageViewOptions. The helper renders escaped src, alt, loading, width, and height attributes; it includes class and decoding when configured. loading defaults to lazy and decoding defaults to async.
<?php
use Lemonade\Framework\Image\ImageViewOptions;
use Lemonade\Framework\Image\Value\ImageDimensions;
use Lemonade\Framework\Image\Value\ImageFormat;
use Lemonade\Framework\Image\Value\ImageReference;
$avatar = new ImageReference(
publicPath: 'images/avatars/jane.webp',
dimensions: new ImageDimensions(320, 320),
format: ImageFormat::Webp,
);
echo $helpers->image(
$avatar,
new ImageViewOptions(
alt: 'Jane Doe',
class: 'rounded-circle',
loading: 'lazy',
),
);
Keep an optional image optional
Pass a nullable reference directly to $helpers->image(). When the reference is null, the helper returns an empty string, so a view does not need a separate conditional just to omit image markup.
<?php
use Lemonade\Framework\Image\Value\ImageReference;
/** @var ImageReference|null $avatar */
$avatar = null;
echo $helpers->image($avatar);
// ''