Detect Image Orientation

  • Is it possible to detect whether an uploaded image is landscape or portrait?


    My aim on the front-end is to change the CSS grid column span of the item if an image is 'landscape'


    I've tried using Template Filters, composite field, and even thought about using the 'output' attribute of an image but I'm not sure it's possible.

    My best guess was to use the 'Accessing content' part of Template Filters but I'm not sure it's possible to _just_ access the width or height attributes of an image field.

  • Jay

    Changed the title of the thread from “Detect Orientation” to “Detect Image Orientation”.
  • You can access all the content vars inside a template filter using the $this->content array. Can you see your width and height in there?


    Code
    1. PerchUtil::debug($this->content[$this->Tag->id]);
  • So sorry for the delayed response—I realised I hadn't turned on email notifications for the forum!


    Thanks for the suggestions. I finally figured this out, the solution was something like:


    if($this->content['photo']['w'] > $this->content['photo']['h']) {

    return 'this is landscape';

    };


    Template filters are my favourite 'hidden' feature of Perch! So so useful.