1

Expecting the answer to be using jsInterop but never hurts to ask.

Can the following be done in Blazor:

const img = new Image();
img.onload = function() {
  alert(this.width + 'x' + this.height);
}
img.src = 'http://www.google.com/intl/en_ALL/images/logo.gif';

As seen here:How to get image size (height & width) using JavaScript?

Kayomez
  • 33
  • 5

1 Answers1

1

I was able to get this done with SixLabors.ImageSharp nuget on Blazor Wasm.

protected async override Task OnInitializedAsync()
{
    var data = await client.GetByteArrayAsync(ImageUrl);
    using(var img = SixLabors.ImageSharp.Image.Load(data))
    {
        Console.WriteLine($"{img.Height}");
    }
}

I'm not sure if it worth the additional assembly. Probably the JS interop is better for this.

Zsolt Bendes
  • 2,219
  • 12
  • 18