Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-08T11:50:42.573Z
Answers.LastActivityDate: 2020-09-25T07:11:12.290Z
Answers.LastEditDate: 2020-09-25T07:11:12.290Z
Answers.UserDisplayName: James Smith
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-07T14:53:00.263Z
Answers.LastActivityDate: 2019-11-07T14:53:00.263Z
Answers.UserDisplayName: outline4
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-17T07:06:06.320Z
Answers.LastActivityDate: 2017-08-17T07:06:06.320Z
Answers.UserDisplayName: justussimon91
Body: <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>
  
Tags: <image-transforms>
Title: Can you prevent upscaling when using Craft's image transforms?
ThreadText: # 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](https://github.com/craftcms/cms/issues/844 "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)
  } %}
  
  <img src="{{ image.getUrl(transform) }}">
  
  ```
  
  
  ---
  
  ### 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'
  } %}
  
  <img src="{{ image.url(transform) }}" alt="" />
  
  ```
  
  
  ---
  
  