I'm looking to create an image transformation where either the height is (e.g.) 180px, or the width is 180px depending on whether the image is portrait or landscape.

So, if the image is landscape the dimensions should be (WxH): 180 x AUTO If the Image is portrait, the dimensions should be (WxH): AUTO x 180

Maybe I'm missing something obvious. Or maybe this could be a CSS issue?


1 Answer 1


A similar question has already been asked here: Is there a way to find out if images (assets) are landscape or portrait?

You will need to create the two asset transforms you mentioned in your question, and then in your template code use an if/else statement to determine which transform to use, depending on if the asset is portrait or landscape.

Thanks to Josh for the code, this is taken from his answer:

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

{% if myImage.getWidth() < myImage.getHeight() %}
  {# portrait #}
{% elseif myImage.getWidth() > myImage.getHeight() %}
  {# landscape #}
{% else %}
  {# square #}
{% endif %}
  • Ah, yes. I was looking for a transformation rather than an in-template solution, but that's fine. Thanks
    – lowe_22
    Commented Dec 9, 2015 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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