10

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.

1 Answer 1

11

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 %}
2
  • Seems like that’s it. Somehow i must have overlooked those. Gonna try this. Thanks! Aug 6, 2014 at 12:54
  • No problem, happy to help :) Aug 6, 2014 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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