Skip to content

Instantly share code, notes, and snippets.

Add image orientation method/property to PageImage objects
<?php
/**
* Gets the orientation of an image
*/
declare(strict_types=1);
namespace ProcessWire;
$getOrientation = fn (Pageimage $image) => $image->width > $image->height ? 'landscape' : 'portrait';
wire()->addHookProperty(
'Pageimage::orientation',
fn (HookEvent $e) => $e->return = $getOrientation($e->object)
);
wire()->addHookMethod(
'Pageimage::orientation',
fn (HookEvent $e) => $e->return = $getOrientation($e->object)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment