Last active
June 19, 2019 09:32
-
-
Save clivewalker/545337ec948c6edd00ec1ea2d7cca15e to your computer and use it in GitHub Desktop.
A Perch CMS template filter to detect whether an image is portrait or landscape orientation. Written by Jay George.
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
/* GROUP IMAGE ORIENTATION DETECTION | |
=================================================== */ | |
class PerchTemplateFilter_image_orientation_detection extends PerchTemplateFilter | |
{ | |
/* Notes... | |
You may want to do something different if the image is landscape e.g. span 2 columns in a CSS grid rather than 1 | |
- Assumes your template image has an ID of `image` | |
- e.g. `<div class="c-photo-grid__item c-photo-grid__item--<perch:content id="image" filter="image-orientation-detection" />">` | |
This would either output `c-photo-grid__item--landscape` or `c-photo-grid__item--portrait` | |
*/ | |
public function filterAfterProcessing($value, $valueIsMarkup = false) | |
{ | |
if($this->content['image']['w'] > $this->content['image']['h']) { | |
return 'landscape'; | |
} else { | |
return 'portrait'; | |
} | |
} | |
} | |
PerchSystem::register_template_filter('image-orientation-detection', 'PerchTemplateFilter_image_orientation_detection'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment