Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a current project we will list entries in a masonry-style grid view where the entry’s respective cover image should be styled differently based on their image format. Landscape vs. portrait and -- of course -- square.

I haven’t found anything on here or in the docs pointing to a possible way of doing this.

share|improve this question
up vote 8 down vote accepted

How about just using the getHeight() and getWidth() methods available on the AssetFileModel? Something like this:

{% set myImage = entry.imagesField.first %}

{% if myImage.getWidth() < myImage.getHeight() %}
  {# portrait #}
{% elseif myImage.getWidth() > myImage.getHeight() %}
  {# landscape #}
{% else %}
  {# square #}
{% endif %}
share|improve this answer
Seems like that’s it. Somehow i must have overlooked those. Gonna try this. Thanks! – Marcus Scheller Aug 6 '14 at 12:54
No problem, happy to help :) – Josh Angell Aug 6 '14 at 12:57

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.