Created
November 6, 2024 17:52
Add image orientation method/property to PageImage objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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