Answers.Body: <p>FWIW, I would not recommend doing image resizing via your Twig templates, because it will do them on page load time. Rather, I’d recommend doing them via an Optimized Images field as per: <a href="https://github.com/nystudio107/craft-imageoptimize/blob/v1/README.md#dynamically-creating-optimized-image-variants" rel="nofollow noreferrer">https://github.com/nystudio107/craft-imageoptimize/blob/v1/README.md#dynamically-creating-optimized-image-variants</a></p>
  
  <p>But if you really want to do it, the parameter there is the same as you’d use for regular Craft transforms: <a href="https://docs.craftcms.com/v3/image-transforms.html#defining-transforms-in-your-templates" rel="nofollow noreferrer">https://docs.craftcms.com/v3/image-transforms.html#defining-transforms-in-your-templates</a></p>
  
  <p>So you could do <code>'top-center'</code> or such</p>
  
  <p>But especially since you’re just creating one image variant, there’s no real advantage to doing this via ImageOptimize in your templates. Just use a regular Craft transform. With ImageOptimize installed, the resulting image will be optimized when done via Craft transforms, too. </p>
  
  <p>The real benefit of using ImageOptimize to create image transforms is to make creating responsive image <code>srcset</code>s easier. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-30T06:11:49.613Z
Answers.Text: thanks for your answer, I did not know about all the features of the plugin, Optimized Images field is a cool feature in the plugin.
Answers.UserDisplayName: Girish
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-29T16:23:14.440Z
Answers.LastActivityDate: 2018-11-30T03:40:07.397Z
Answers.LastEditDate: 2018-11-30T03:40:07.397Z
Answers.UserDisplayName: andrew.welch
Body: <p>I am using imageoptimize plugin to crop images, but I am unable to find cropping position setup in a template.</p>
  
  <pre><code>{% set optimzedImages = craft.imageOptimize.createOptimizedImages(
         entry.backgroundImage.one(),
            [
                      {
                          'width': 1440,
                          'useAspectRatio': true,
                          'aspectRatioX': 1.0,
                          'aspectRatioY': 0.35,
                          'retinaSizes': ['1'],
                          'quality': 82,
                          'format': entry.backgroundImage.one().extension,
                          'position' : 'top-center'
                      }
                  ]
              ) %}
  </code></pre>
  
  <p>The above code is cropping image in <code>center-center</code> and I want to crop an image from top to aspect ratio height.</p>
  
Tags: <craft3><plugin-imageoptimize>
Title: craft-imageoptimize plugin cropping position
ThreadText: # craft-imageoptimize plugin cropping position
  
  (Asked by: username_0 on 2018-11-29)
  
  I am using imageoptimize plugin to crop images, but I am unable to find cropping position setup in a template.
  
  ```
  {% set optimzedImages = craft.imageOptimize.createOptimizedImages(
         entry.backgroundImage.one(),
            [
                      {
                          'width': 1440,
                          'useAspectRatio': true,
                          'aspectRatioX': 1.0,
                          'aspectRatioY': 0.35,
                          'retinaSizes': ['1'],
                          'quality': 82,
                          'format': entry.backgroundImage.one().extension,
                          'position' : 'top-center'
                      }
                  ]
              ) %}
  
  ```
  
  The above code is cropping image in `center-center` and I want to crop an image from top to aspect ratio height.
  
  **Tags:** craft3, plugin-imageoptimize
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-11-29. Score: 2 | Accepted answer
  
  FWIW, I would not recommend doing image resizing via your Twig templates, because it will do them on page load time. Rather, I’d recommend doing them via an Optimized Images field as per: <https://github.com/nystudio107/craft-imageoptimize/blob/v1/README.md#dynamically-creating-optimized-image-variants>
  
  But if you really want to do it, the parameter there is the same as you’d use for regular Craft transforms: <https://docs.craftcms.com/v3/image-transforms.html#defining-transforms-in-your-templates>
  
  So you could do `'top-center'` or such
  
  But especially since you’re just creating one image variant, there’s no real advantage to doing this via ImageOptimize in your templates. Just use a regular Craft transform. With ImageOptimize installed, the resulting image will be optimized when done via Craft transforms, too.
  
  The real benefit of using ImageOptimize to create image transforms is to make creating responsive image `srcset`s easier.
  
  > **Comments:**
  > **username_0**: thanks for your answer, I did not know about all the features of the plugin, Optimized Images field is a cool feature in the plugin.  
  
  ---
  
  