<p>As of Craft 3.4 you can set <code>upscaleImages</code> to false in general config: <a href="https://craftcms.com/docs/3.x/config/config-settings.html#upscaleimages" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/config/config-settings.html#upscaleimages</a></p>

CC BY-SA 4.0
2020-07-08T11:50:42.573Z
2020-09-25T07:11:12.290Z
2020-09-25T07:11:12.290Z
James Smith
<p>If you want to work with transforms you've created in the backend you can use this: </p>

<pre><code>{% set transformDimensions = craft.app.assetTransforms.getTransformByHandle('contentWidth') %}
{% set transform = {
    width: min(transformDimensions.width, image.width),
    mode: 'fit'
} %}

&lt;img src="{{ image.url(transform) }}" alt="" /&gt;
</code></pre>

CC BY-SA 4.0
2019-11-07T14:53:00.263Z
2019-11-07T14:53:00.263Z
outline4
<p>As found <a href="https://github.com/craftcms/cms/issues/844" rel="noreferrer" title="here">here</a>, this actually seems to be a requested feature that is not yet implemented. However, in the link given, Brandon also supplied a workaround for the time being:</p>

<pre><code>{% set transform = {
width: min(150, image.width),
height: min(100, image.height)
} %}

&lt;img src="{{ image.getUrl(transform) }}"&gt;
</code></pre>

CC BY-SA 3.0
2017-08-17T07:06:06.320Z
2017-08-17T07:06:06.320Z
justussimon91
<p>With <a href="https://craftcms.com/docs/image-transforms" rel="noreferrer">Craft's image transforms</a> used to resize images or generate thumbnails, can you prevent images from being <em>upscaled</em>? There's often cases where it makes no sense to <em>increase</em> the dimensions of an image.</p>

<p>It would be great if there was a setting for this, but I can't find one documented.</p>

<p>Otherwise, is the solution to fetch the image size in Twig and then <em>conditionally</em> apply the image transform?</p>

<image-transforms>
Can you prevent upscaling when using Craft's image transforms?
# Can you prevent upscaling when using Craft's image transforms?

(Asked by: username_0 on 2017-08-17)

With [Craft's image transforms](https://craftcms.com/docs/image-transforms) used to resize images or generate thumbnails, can you prevent images from being *upscaled*? There's often cases where it makes no sense to *increase* the dimensions of an image.

It would be great if there was a setting for this, but I can't find one documented.

Otherwise, is the solution to fetch the image size in Twig and then *conditionally* apply the image transform?

**Tags:** image-transforms


---

## 3 answers

### Answer by username_3 on 2017-08-17. Score: 8 | Accepted answer

As found here, this actually seems to be a requested feature that is not yet implemented. However, in the link given, Brandon also supplied a workaround for the time being:
{% set transform = {
width: min(150, image.width),
height: min(100, image.height)
} %}


---

### Answer by username_1 on 2020-07-08. Score: 4

As of Craft 3.4 you can set `upscaleImages` to false in general config: <https://craftcms.com/docs/3.x/config/config-settings.html#upscaleimages>


---

### Answer by username_2 on 2019-11-07. Score: 2

If you want to work with transforms you've created in the backend you can use this: 
{% set transformDimensions = craft.app.assetTransforms.getTransformByHandle('contentWidth') %}
{% set transform = {
    width: min(transformDimensions.width, image.width),
    mode: 'fit'
} %}


---

