<p>As Andris Sevcenko pointed out, the problem is Craft 3 Beta 22 and a Multisite Configuration. Fixed in Beta 23.</p>

CC BY-SA 3.0
2017-08-09T21:13:02.423Z
2017-08-09T21:13:02.423Z
Matthias Redl-Mann
<p>In my Craft 3 Plugin I am saving an image (YouTube poster) to an asset volume like this:</p>

<pre><code>$asset = new Asset();
$asset-&gt;title = $url;
$asset-&gt;tempFilePath = $tmpPath; // temp path for image in /storage/runtime/temp/
$asset-&gt;volumeId = $volumeId; // ID of my Asset Volume
$asset-&gt;filename = $filename; // filename like youtube_&lt;youTubeKey&gt;.jpg
$asset-&gt;newFolderId = $folder-&gt;id; // root folder id of the volume
$asset-&gt;avoidFilenameConflicts = true;
$asset-&gt;setScenario(Asset::SCENARIO_CREATE);
clearstatcache();
list ($w, $h) = Image::imageSize($tmpPath);
$asset-&gt;setWidth($w);
$asset-&gt;setHeight($h);
$result = Craft::$app-&gt;getElements()-&gt;saveElement($asset);
</code></pre>

<p>The image saved does not have width or height (so it's there while saving), so if I later output its width like this in TWIG: <code>{{ dump(img.width) }}</code> it will be <code>NULL</code>.</p>

<p>Any hints what I need to call so that craft persists the image width / height?</p>

CC BY-SA 3.0
2017-08-09T08:13:06.887Z
You shouldn't set the width/height yourself, but that shouldn't matter. Is there a chance that you're using multisite and this is earlier than Craft 3.0.0-beta23? If so, you should update Craft. If not, you should get in touch via support@craftcms.com
Andris Sevcenko
CC BY-SA 3.0
2017-08-09T08:34:31.283Z
Hi Andris, yes multisite & beta 22. I filed the bug that you fixed. But I can't update at the moment, 23 has a severe bug for me. ok, then I will wait
Matthias Redl-Mann
<plugin-development><image><twigextension>
Craft 3 Plugin: Saved image asset has no width / height
# Craft 3 Plugin: Saved image asset has no width / height

(Asked by: username_0 on 2017-08-08)

In my Craft 3 Plugin I am saving an image (YouTube poster) to an asset volume like this:
$asset = new Asset();
$asset->title = $url;
$asset->tempFilePath = $tmpPath; // temp path for image in /storage/runtime/temp/
$asset->volumeId = $volumeId; // ID of my Asset Volume
$asset->filename = $filename; // filename like youtube_.jpg
$asset->newFolderId = $folder->id; // root folder id of the volume
$asset->avoidFilenameConflicts = true;
$asset->setScenario(Asset::SCENARIO_CREATE);
clearstatcache();
list ($w, $h) = Image::imageSize($tmpPath);
$asset->setWidth($w);
$asset->setHeight($h);
$result = Craft::$app->getElements()->saveElement($asset);

The image saved does not have width or height (so it's there while saving), so if I later output its width like this in TWIG: {{ dump(img.width) }} it will be NULL.
Any hints what I need to call so that craft persists the image width / height?

**Tags:** plugin-development, image, twigextension

> **Comments:**
> **username_1**: You shouldn't set the width/height yourself, but that shouldn't matter. Is there a chance that you're using multisite and this is earlier than Craft 3.0.0-beta23? If so, you should update Craft. If not, you should get in touch via support@craftcms.com  
> **username_0**: Hi Andris, yes multisite & beta 22. I filed the bug that you fixed. But I can't update at the moment, 23 has a severe bug for me. ok, then I will wait  

---

## 1 answers

### Answer by username_0 on 2017-08-09. Score: 1 | Accepted answer

As username_1 pointed out, the problem is Craft 3 Beta 22 and a Multisite Configuration. Fixed in Beta 23.


---

