<p>Eager loading is used to reduce the number of database queries. Imager doesn't store any data in the database, it's completely file-based, so it's not relevant to use eager-loading in relation to it.</p>

CC BY-SA 4.0
2019-07-23T15:58:48.527Z
But since Craft can [eager-load image transforms](https://docs.craftcms.com/v3/dev/eager-loading-elements.html#eager-loading-image-transform-indexes) using the `withTransforms` parameter, it would make sense that there should also be a way to have it eager-load Imager transforms, no?
Sandwich
CC BY-SA 3.0
2018-04-11T18:16:35.957Z
2018-04-11T18:16:35.957Z
André Elvan
<p>I am using <a href="https://github.com/aelvan/Imager-Craft" rel="nofollow noreferrer">Imager</a> to create my image transforms. I am on a category page and I want to list all of the products. </p>

<p>I did a quick <code>.with(['cf_shop_assets'])</code> optimization and wanted to continue with the image transforms. </p>

<p>Frankly, I don't know where to start? </p>

<pre class="lang-html prettyprint-override"><code>{% set products = craft.commerce.products.relatedTo(category).with(['cf_shop_assets']) %}
{% if products|length %}
    &lt;div class="shop_container block listing_format"&gt;
        {% for product in products %}

        {% set variants = product.variants %}
        {% set variant = product.defaultVariant %}

        &lt;div class="shop_item"&gt;
            &lt;div class="more_info"&gt;
                &lt;a href="{{ product.url }}"&gt;
                    {% set image = product.cf_shop_assets[0] ?? null %}
                    {% if image|length %}
                        {% set transformedImage = craft.imager.transformImage(image, {
                            width: 300,
                            quality: 90,
                            format: 'jpg',
                            bgColor: '#EFEFDE',
                            effects: { sharpen: true }
                        }) %}
                        &lt;figure&gt;
                            &lt;img src="{{ transformedImage.url }}" class="image_full_width" width="{{ transformedImage.width }}" height="{{ transformedImage.height }}" alt="{{ image.title }} {{ gl_meta.cf_altText }}" /&gt;
                        &lt;/figure&gt;
                    {% endif %}
                    &lt;h2&gt;{{ product.title }}&lt;/h2&gt;
                &lt;/a&gt;
            &lt;/div&gt;

            […]

        {% endfor %}
    &lt;/div&gt;
{% endif %}
</code></pre>

<p>The code works, but it only saves about 5 queries. </p>

<p>Would somebody be so kind to show me how to eager load Imager transforms? </p>

<p>I need Imager because I don't want to use transparent PNGs. There's no native way to transform a PNG to JPG and adding a background color. </p>

<p>Is this even possible? </p>

CC BY-SA 3.0
2018-03-04T18:11:35.347Z
Those plugin related questions are always difficult to answer because we have to dig deep into the plugin - unless the creator appears. I would suggest you to contact the creator directly and ask him. I doubt it's possible but maybe he could help you create this feature
Robin Schambach
<plugin-craftcommerce><eager-loading><plugin-imager>
Eager load Imager transforms in Craft Commerce
# Eager load Imager transforms in Craft Commerce

(Asked by: username_0 on 2018-03-02)

I am using Imager to create my image transforms. I am on a category page and I want to list all of the products. 
I did a quick .with(['cf_shop_assets']) optimization and wanted to continue with the image transforms. 
Frankly, I don't know where to start? 
{% set products = craft.commerce.products.relatedTo(category).with(['cf_shop_assets']) %}
{% if products|length %}
    
        {% for product in products %}

        {% set variants = product.variants %}
        {% set variant = product.defaultVariant %}

        
            
                
                    {% set image = product.cf_shop_assets[0] ?? null %}
                    {% if image|length %}
                        {% set transformedImage = craft.imager.transformImage(image, {
                            width: 300,
                            quality: 90,
                            format: 'jpg',
                            bgColor: '#EFEFDE',
                            effects: { sharpen: true }
                        }) %}
                        
                            
                        
                    {% endif %}
                    {{ product.title }}
                
            

            […]

        {% endfor %}
    
{% endif %}

The code works, but it only saves about 5 queries. 
Would somebody be so kind to show me how to eager load Imager transforms? 
I need Imager because I don't want to use transparent PNGs. There's no native way to transform a PNG to JPG and adding a background color. 
Is this even possible?

**Tags:** plugin-craftcommerce, eager-loading, plugin-imager

> **Comments:**
> **username_1**: Those plugin related questions are always difficult to answer because we have to dig deep into the plugin - unless the creator appears. I would suggest you to contact the creator directly and ask him. I doubt it's possible but maybe he could help you create this feature  

---

## 1 answers

### Answer by username_2 on 2018-04-11. Score: 3 | Accepted answer

Eager loading is used to reduce the number of database queries. Imager doesn't store any data in the database, it's completely file-based, so it's not relevant to use eager-loading in relation to it.

> **Comments:**
> **username_3**: But since Craft can [eager-load image transforms](https://docs.craftcms.com/v3/dev/eager-loading-elements.html#eager-loading-image-transform-indexes) using the `withTransforms` parameter, it would make sense that there should also be a way to have it eager-load Imager transforms, no?  

---

