Skip to content

Instantly share code, notes, and snippets.

@clivewalker
Last active June 19, 2019 09:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clivewalker/545337ec948c6edd00ec1ea2d7cca15e to your computer and use it in GitHub Desktop.
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.
/* 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