Is it possible to define an aspect ratio / set a max height on an image transform, without using a plugin?

Let's say the width is fixed to 600px, but the height can be any value up to 800px?

1 Answer 1


You can pass an array instead of the image-transform handle to the getUrl() function

{% set transform = {
    'width' => 600,
    'height' => (asset.getWidth() <= 800)? asset.getWidth() : 800
} %}
{{ asset.getUrl(transform) }}

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.