i´m implementing a image gallery and want to show the thumbnails ( no problem here ) with a transform applied, and i want to implement a image transform on the large image that opens on a lightbox. Why? because it´s a responsive website, and the load speed is crucial, and don´t want to slow things down loading the full image uploaded directly from the client camera ( 6mp or more ), i want to load a large image with a max width of 1000px and jpg quality of 70. I applied the transform and works fine, but the images below 1000px are streted to fit 1000px.

So, my question is: how to set max width of an image to 1000px BUT not forcing it if it´s smaller than the required size?

Crop Fit and Scales don´t do the job.

Any help is welcome! Thanks.

1 Answer 1


Before you run your transform, you can check the width of the asset file and adjust your transform as needed.

{% set thumb = {
    mode: 'scale',
    width: 1000,
    quality: 70,
} %}

{% if asset.width < 1000 %}

    {% set thumb = {
        mode: 'scale',
        width: asset.width,
        quality: 70,
    } %}

{% endif %}
  • Thanks for your reply, but i get errors using your code... This solved it out: craftcms.stackexchange.com/questions/3045/…
    – Seba.
    Commented Oct 29, 2015 at 19:17
  • Glad you got it sorted out! Commented Oct 29, 2015 at 22:27
  • Would you mind posting an answer here @Seba, or deleting the question if it seems like a duplicate?
    – Matt Stein
    Commented May 9, 2017 at 23:13

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.