<p>Have you checked the documentation for your plugin? You can <a href="https://nystudio107.com/docs/image-optimize/using.html#using-the-optimized-images-field" rel="nofollow noreferrer">configure image variants and force specific aspect ratios</a> in the field settings. If you don't want to configure those sizes for the entire field, but only in a specific place in your template, see dynamically <a href="https://nystudio107.com/docs/image-optimize/using.html#dynamically-creating-optimized-image-variants" rel="nofollow noreferrer">creating optimized image variants</a> in the documentation.</p>
<p>I haven't used this plugin before, but based on your example code and the documentation linked above, something like this should work:</p>
<pre><code>{% set optimizedImages = craft.imageOptimize.createOptimizedImages(
    works.artwork.one(),
    [
        {
            'width': 200,
            'useAspectRatio': true,
            'aspectRatioX': 1.0,
            'aspectRatioY': 1.0,
            'retinaSizes': ['1'],
            'quality': 82,
            'format': 'jpg',
        },
    ]
) %}

</code></pre>

CC BY-SA 4.0
2021-07-15T08:25:27.773Z
Hi MoritzLost, Thanks for your reply.  I read that creating variants in the template would slow things down.  I have read the docs but I was struggling to find how it was done in field settings.  I have now realised it's possible to have multiple Image Optimize field types for different jobs (thumbnails, natural...) on the same page.  Once I discovered this I got it working.
Martin
CC BY-SA 4.0
2021-07-15T09:42:34.480Z
@Martin Glad I could help! If your issue is solved, would you mind marking my answer as accepted? Thanks.
MoritzLost
CC BY-SA 4.0
2021-07-14T15:02:29.387Z
2021-07-14T15:02:29.387Z
MoritzLost
<p>Please forgive me if this is an idiot question.  How do I obtain 'crop' and 'scale' with Image Optimize??  I would like a page of equally sized images (height &amp; width) which are cropped from the center. This is easy with a Craft transform .url('thumbs'), but what do I need to do to the following code to achieve this?</p>
<pre><code>         {% set optimizedImages = works.artwork.one().fd_optimizedThumbs %}

         &lt;img class=&quot;lazyload&quot; src=&quot;{{ optimizedImages.placeholderImage() }}&quot;
         data-srcset=&quot;{{ optimizedImages.srcset() }}&quot;
         sizes=&quot;100vw&quot; /&gt;
</code></pre>
<p>Many thanks</p>

<plugin-imageoptimize>
Cropping with NY Studio Image Optimize Plugin
# Cropping with NY Studio Image Optimize Plugin

(Asked by: username_0 on 2021-07-14)

Please forgive me if this is an idiot question.  How do I obtain 'crop' and 'scale' with Image Optimize??  I would like a page of equally sized images (height & width) which are cropped from the center. This is easy with a Craft transform .url('thumbs'), but what do I need to do to the following code to achieve this?
         {% set optimizedImages = works.artwork.one().fd_optimizedThumbs %}

         

Many thanks

**Tags:** plugin-imageoptimize

---

## 1 answers

### Answer by username_1 on 2021-07-14. Score: 1 | Accepted answer

Have you checked the documentation for your plugin? You can configure image variants and force specific aspect ratios in the field settings. If you don't want to configure those sizes for the entire field, but only in a specific place in your template, see dynamically creating optimized image variants in the documentation.
I haven't used this plugin before, but based on your example code and the documentation linked above, something like this should work:
{% set optimizedImages = craft.imageOptimize.createOptimizedImages(
    works.artwork.one(),
    [
        {
            'width': 200,
            'useAspectRatio': true,
            'aspectRatioX': 1.0,
            'aspectRatioY': 1.0,
            'retinaSizes': ['1'],
            'quality': 82,
            'format': 'jpg',
        },
    ]
) %}

> **Comments:**
> **username_0**: Hi MoritzLost, Thanks for your reply.  I read that creating variants in the template would slow things down.  I have read the docs but I was struggling to find how it was done in field settings.  I have now realised it's possible to have multiple Image Optimize field types for different jobs (thumbnails, natural...) on the same page.  Once I discovered this I got it working.  
> **username_1**: @Martin Glad I could help! If your issue is solved, would you mind marking my answer as accepted? Thanks.  

---

