Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.