0

I am working on requirement where during upload image from user on ASP.net form, I need to check if user provided image is greater than 500kb then I don't need to reduce the size of the image if it is above the size then reduce the size of the image but when I tried to use FileSize property it always show 0 value. I am using below code.

using (MagickImageCollection collection = new MagickImageCollection(txtInput.Text))
{
    collection.Coalesce();

    foreach (MagickImage image in collection)
    {
        if (image.FileSize >= 500)
        {
            image.Quality = 50;
            image.Sample(image.Width / 2, image.Height / 2);
        }
    }
    collection.Write(txtOutput.Text);
}

1 Answers1

2

You are getting 0 for the file size because the frames of the image are not aware of the size of the complete image. I am the author of this library and decided to remove the FileSize property to avoid the confusion. The property has been removed in Magick.NET 7.3.0.0. The standard System.IO library should be sufficient to get the file size of an image.

dlemstra
  • 7,813
  • 2
  • 27
  • 43