Magick.Net resize image

3.6k Views Asked by At

I have some code to convert an image, which is working now, but the width of the image that is generated is really small. I would like to force it to use a width of 600px. My code looks like this:

public async Task<string> ConvertImage(byte[] data)
{

    // Create our settings
    var settings = new MagickReadSettings
    {
        Width = 600
    };

    // Create our image
    using (var image = new MagickImage(data, settings))
    {

        // Create a new memory stream
        using (var memoryStream = new MemoryStream())
        {

            // Set to a png
            image.Format = MagickFormat.Png;
            image.Write(memoryStream);
            memoryStream.Position = 0;

            // Create a new blob block to hold our image
            var blockBlob = container.GetBlockBlobReference(Guid.NewGuid().ToString() + ".png");

            // Upload to azure
            await blockBlob.UploadFromStreamAsync(memoryStream);

            // Return the blobs url
            return blockBlob.StorageUri.PrimaryUri.ToString();
        }
    }
}

The image I have uploaded is an AI file, but when it gets converted it is only 64px wide. Does anyone know why and how I can fix it?

1

There are 1 best solutions below

0
On BEST ANSWER

With the current version of Magick.NET this is the expected behavior. But after seeing your post we made some changes to ImageMagick/Magick.NET. With Magick.NET 7.0.0.0103 and higher you will get an image that fits inside the bounds that you specify with Width and Height. So when you specify a Width of 600 you will get an image that is 600 pixels wide.