How can I base64-encode an Image Transform? I'm trying to use this plugin, but it requires an AssetFileModel as input. I can pass it the asset in question, no problem, but I'm wanting to pass it a transformed version of the asset. However, it seems like there's no way in Craft to pass a transformed image as an AssetFileModel.

Here's my code:

{% set image = assetField.first() %}

{# Doesn't work; `image.url({width: 40})` outputs a URL as a string, not an AssetFileModel #}
{% set imageTiny = image.url({ width: 40 }) | image64(true) %}

&lt;div style="background: url({{ imageTiny }});"&gt;...&lt;/div&gt;


The desired result is for a base64-encoded string of the tiny, 40px-wide image to be output in the HTML.

Any ideas?
It's not going to work with this particular plugin:


        // Require an instance of `AssetFileModel`
        if (! $asset instanceof AssetFileModel)
        {
            // Die quietly.
            return false;
        }


It specifically checks the parameter that you pass in, and expects it to be an AssetFileModel. It wouldn't be too hard to modify the plugin to work for your use-case, though.

I see what you're trying to do; if you're using Craft 3, you could use the ImageOptimize plugin to do it for you.