Skip to content

Responsive Rendering & Template API

MediaAssetItem exposes a ProcessWire-familiar API backed by Media’s self-contained ImageEngine (intervention/image v4.4 + intervention/image-driver-vips + intervention/imagehash, auto-detecting Vips -> Imagick -> GD).

ProcessWire-Familiar Properties & Resize Methods

Section titled “ProcessWire-Familiar Properties & Resize Methods”
Property / Method Description
$img->url, $img->httpUrl, $img->basename, $img->ext, $img->filesizeStr Public file URLs and file metadata
$img->width, $img->height, $img->ratio, $img->description, $img->tags Dimensions, aspect ratio, and metadata
$img->title($lang), $img->alt($lang), $img->caption($lang) Localized metadata for the active or specified Language
$img->webp, $img->avif On-demand WebP or AVIF variation properties
$img->size($w, $h, $opts) / width($w) / height($h) Focus-point-aware resize and crop cached in entries_tbl_media_crops
$img->maxSize($w, $h) / maxWidth($w) / maxHeight($h) Fit inside bounding box without cropping
$img->crop($x, $y, $w, $h) / contain($w, $h, $bgHex) Explicit crop or letterboxed containment
$img->ensureCrop($presetHandle, $fallbackW, $fallbackH) Return named crop preset (respecting is_manual = 1 locks)
$img->watermark($opts) / clearVariations() / lqip(true) Apply watermark, purge non-manual crops, or lazily regenerate LQIP

Responsive <picture>, Art Direction & Retina 1x/2x

Section titled “Responsive <picture>, Art Direction & Retina 1x/2x”

$asset->render(), $asset->attrs(), and $asset->pictureHtml() preserve fixed aspect ratios across numeric dimensions, dynamic shorthands (16:9, landscape-1-2, square-1-3 via CropService::calculate()), named presets, and manual-locked Crop Studio frames:

<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Media\Entity\MediaAssetItem;
$lang = $languages ? $user->language : null;
$hero = $page->hero_media->first();
if ($hero instanceof MediaAssetItem) {
// Full responsive <picture> with AVIF/WebP <source>, original-format fallback <img>,
// art direction for mobile viewports, and LCP fetchpriority="high"
echo $hero->render(1600, 900, [
'isFirst' => true,
'alt' => $hero->alt($lang),
'class' => 'hero-image',
'pictureClass' => 'hero-picture',
'webpAdd' => true,
'avifAdd' => true,
'artDirection' => [
'(max-width: 767px)' => ['width' => 640, 'height' => 800, 'sizes' => '100vw'],
],
]);
// Fixed-size UI element with Retina 1x/2x density descriptors (automatically omits sizes)
echo $hero->render('square-1-3', null, [
'densities' => [1, 2],
'descriptor' => 'x',
'alt' => $hero->alt($lang),
]);
}

One-Call Public Resolution & Progressive Lazy Load

Section titled “One-Call Public Resolution & Progressive Lazy Load”
  • Media::resolvePublicAsset($val) & Media::renderResponsive($val, $opts): Resolve any UUID, MediaAssetItem, MediaAssetArray, or DTO into a published public asset (isPublished() ensures approved and non-embargoed) and output responsive <picture> markup in one call.
  • Progressive Fade-In (inline_lazyload): When enabled in settings or $config->media, lazy images (never isFirst => true LCP images) receive media-lazyload, and Media injects a minimal prefers-reduced-motion-aware CSS/JS snippet before </head> only on pages containing media-lazyload (with optional $config->media['csp_nonce']).
  • Codec Safeguards: Uploads are automatically EXIF-oriented and stripped via ImageEngine::normalizeAndStrip(), JPEG variations encode progressively, and animated GIF/WebP files bypass single-frame rasterization (ImageEngine::isAnimated()) to preserve animation frames.

Video Posters & Privacy-Friendly Embed Facades

Section titled “Video Posters & Privacy-Friendly Embed Facades”

For video, PDF, or YouTube/Vimeo embed assets, read $asset->posterUrl() or render a click-to-play facade that loads zero third-party scripts until clicked:

<?php
declare(strict_types=1);
namespace ProcessWire;
echo $videoAsset->embedHtml([
'facade' => true,
'class' => 'aspect-video w-full rounded-xl',
]);

Visual Intelligence (Intervention Image v4.4 + ImageHash)

Section titled “Visual Intelligence (Intervention Image v4.4 + ImageHash)”

Every image asset exposes built-in color and perceptual hashing methods without external APIs:

<?php
declare(strict_types=1);
namespace ProcessWire;
$primaryHex = $hero->dominantColor();
$palette = $hero->palette(6);
$theme = $hero->colorTheme(); // 'light' or 'dark'
$hash = $hero->imageHash('dhash');
$isDuplicate = $hero->isSimilar($otherAsset);
$distance = $hero->hashDistance($otherAsset);

Next steps