Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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

1 Answer 1

up vote 5 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 at 12:54
    
No problem, happy to help :) –  joshangell Aug 6 at 12:57

Your Answer

 
discard

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.