<p>There’s a discussion on that question, here at <a href="https://craftcms.stackexchange.com/questions/37610/twig-dataurl-function-for-resized-images/40655?noredirect=1#comment48561_40655">Stackexchange</a>. There I wrote:</p>
<p>It’s not possible to get a dataUrl from a resized asset at this time, not even in Craft 4.</p>
<p>There’s already an issue for that: <a href="https://github.com/craftcms/cms/discussions/11388" rel="nofollow noreferrer">https://github.com/craftcms/cms/discussions/11388</a>.</p>
<p>In an older, closed issue, the reason is explained: <a href="https://github.com/craftcms/cms/issues/10108" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/10108</a>.</p>
<p>It is said to be possible with the <a href="https://plugins.craftcms.com/imager-x" rel="nofollow noreferrer">Imager X plugin.</a> And there is a dedicated <a href="https://plugins.craftcms.com/blur-hash" rel="nofollow noreferrer">Blur Hash Plugin</a>.</p>
<p>However: We are discussing and testing it currently. Best will be to read the discussion.</p>

CC BY-SA 4.0
2023-04-12T20:31:05.903Z
2023-04-12T20:31:05.903Z
Moritz
<p>I'm generating base64 encoded strings of very small image transforms to display a blurred version of images while the bigger asset is loading.</p>
<p>I'm trying to get the cached transform path (if it already exists) as I need to extract the actual file content via <code>file_get_contents()</code>.</p>
<p>I tried this:</p>
<pre><code>$asset-&gt;setTransform('rendition8')-&gt;getCopyOfFile()
</code></pre>
<p>But this returns the original asset path, so <code>setTransform</code> is ignored.</p>
<p>The workaround I currently use is:</p>
<pre><code>$url = $asset-&gt;getUrl('rendition8');
$baseUrl = UrlHelper::siteUrl();
$imgUrl = str_replace($baseUrl, '/', $url);
$fullPath = Craft::getAlias('@storage') . $imgUrl;
</code></pre>
<p>Which is not great...</p>
<p>Is there any other asset method I'm missing?
Maybe it just doesn't exist because the transformed resource might not be generated yet?</p>
<p>Thanks!</p>

<assets><image-transforms>
Retrieve storage path of image transform instead of URL
# Retrieve storage path of image transform instead of URL

(Asked by: username_0 on 2022-12-13)

I'm generating base64 encoded strings of very small image transforms to display a blurred version of images while the bigger asset is loading.
I'm trying to get the cached transform path (if it already exists) as I need to extract the actual file content via file_get_contents().
I tried this:
$asset->setTransform('rendition8')->getCopyOfFile()

But this returns the original asset path, so setTransform is ignored.
The workaround I currently use is:
$url = $asset->getUrl('rendition8');
$baseUrl = UrlHelper::siteUrl();
$imgUrl = str_replace($baseUrl, '/', $url);
$fullPath = Craft::getAlias('@storage') . $imgUrl;

Which is not great...
Is there any other asset method I'm missing?
Maybe it just doesn't exist because the transformed resource might not be generated yet?
Thanks!

**Tags:** assets, image-transforms

---

## 1 answers

### Answer by username_1 on 2023-04-12. Score: 2

There’s a discussion on that question, here at [Stackexchange](https://craftcms.stackexchange.com/questions/37610/twig-dataurl-function-for-resized-images/40655?noredirect=1#comment48561_40655). There I wrote:

It’s not possible to get a dataUrl from a resized asset at this time, not even in Craft 4.

There’s already an issue for that: <https://github.com/craftcms/cms/discussions/11388>.

In an older, closed issue, the reason is explained: <https://github.com/craftcms/cms/issues/10108>.

It is said to be possible with the [Imager X plugin.](https://plugins.craftcms.com/imager-x) And there is a dedicated [Blur Hash Plugin](https://plugins.craftcms.com/blur-hash).

However: We are discussing and testing it currently. Best will be to read the discussion.


---

