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_<youTubeKey>.jpg
$asset->newFolderId = $folder->id; // root folder id of the volume
$asset->avoidFilenameConflicts = true;
list ($w, $h) = Image::imageSize($tmpPath);
$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?

  • 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 – Andris Sevcenko Aug 9 '17 at 8:13
  • 1
    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 Aug 9 '17 at 8:34

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.