Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get image dimensions when is stored in azure blob storage?

I have image in blob and I want to read image dimensions (width and height)

This is my function to read from blob:

 private static CloudBlockBlob ReadBlockBlob(string input, IConfigurationRoot config)
    {
        CloudStorageAccount storageAccount = new CloudStorageAccount(
            new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(config["storageAccountName"], config["storageKeyValue"]), true);
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference(config["blobContainer"]);
        return container.GetBlockBlobReference(input);
    }

I don't see any useful metadata in CloudBlobContainer nor in CloudBlockBlob.

Any idea how to get dimensions of image from blob?

Thank you

like image 381
Raskolnikov Avatar asked Jan 28 '26 15:01

Raskolnikov


1 Answers

You can not directly get the dimensions of an image blob that exists on Azure Storage via the properties and metadata of the blob. The only way is to download the image blob and convert it to System.Drawing.Image via methods System.Drawing.Image.FromFile or System.Drawing.Image.FromStream to get Image.Width & Image.Height.

Or else, you need to first add metadata to the blob to store the image dimensions when uploading an image. Then, you can get the dimensions of an image from the blob metadata without downloading. I recommend this way to avoid downloading for those large images.

like image 174
Peter Pan Avatar answered Jan 30 '26 05:01

Peter Pan