This project has moved and is read-only. For the latest updates, please go here.

Resize API corrupting image

May 10, 2013 at 11:35 AM
Hi,

I have added MagickNet API (Magick.NET 6.8.5.4) in web application. I am trying to generate the thumbnails out of images using MagickImage.Resize API. Output generate the image that seems replicated same image as a part of thumbnail.

You can see original and modified image uploaded

https://plus.google.com/photos/108639021834884343360/albums/5876294219977625841

Code is as simple as documented, I also tried scale API which generates same result.
        using (MagickImage img = new MagickImage(sourcepath))
        {
            //img.ImageType = type;
            if (sizeInRatio)
            {
                //img.Scale(new Percentage(width.Value), new Percentage(height.Value));
                img.Resize(new Percentage(width.Value), new Percentage(height.Value));
            }
            else
            {
                //img.Scale(width.Value, height.Value);
                img.Resize(width.Value, height.Value);
            }
            img.Write(destinationpath);
        }
Is there anything I am missing? Any help would be appreciated.

Thanks in advance.
May 10, 2013 at 12:18 PM
I am unable to produce the same result. What is the datatype of width/height and what values are you supplying? Can you also tell me the exact version you are using? You can get the version this way:
Console.WriteLine(MagickNet.Version);
The following produces normal outputs for me:
using (MagickImage image = new MagickImage(@"Discussions\Original.gif"))
{
  image.Resize(0.5, 0.5);
  image.Write(@"Discussions\Resized.50%.gif");
}

using (MagickImage image = new MagickImage(@"Discussions\Original.gif"))
{
  image.Resize(150, 150);
  image.Write(@"Discussions\Resized.150.gif");
}
May 10, 2013 at 12:40 PM
Edited May 10, 2013 at 12:41 PM
Thanks for the reply,

I am supplying argument of type .NET int as width and height. However it is nullable data types.

I dont see any Version property assosciated with MagickNet (Net is in capital letters - MagickNET and has Initilize and SetCacheThreshold methods only).

Following is complete function,
    public static void GenerateThumbnail(Stream stream, string destinationpath,
        ImageType type = THUMBNAIL_TYPE, int? width = THUMBNAIL_WIDTH, 
        int? height = THUMBNAIL_HEIGHT, bool sizeInRatio = THUMBNAIL_SCALE_IN_RATIO)
    {
        if (string.IsNullOrEmpty(destinationpath))
        {
            throw new ArgumentException("destination path cannot be empty");
        }

        if (!Directory.Exists(Path.GetDirectoryName(destinationpath)))
        {
            throw new DirectoryNotFoundException(Path.GetDirectoryName(destinationpath));
        }

        if (!width.HasValue || width.Value <= 0)
        {
            throw new ArgumentException("width");
        }

        if (!height.HasValue || height.Value <= 0)
        {
            throw new ArgumentException("height");
        }

        using (MagickImage img = new MagickImage(sourcepath))
        {
            //img.ImageType = type;
            if (sizeInRatio)
            {
                //img.Scale(new Percentage(width.Value), new Percentage(height.Value));
                img.Resize(new Percentage(width.Value), new Percentage(height.Value));

            }
            else
            {
                //img.Scale(width.Value, height.Value);
                img.Resize(width.Value, height.Value);
            }
            img.Write(destinationpath);
        }
        }
    }
May 10, 2013 at 12:42 PM
Are you trying with the image I have uploaded to google photos?
May 10, 2013 at 1:50 PM
I did test with the image you uploaded to google. I am suspecting that you are still using the '6.8.3.10' version of Magick.NET.dll. In changeset 25941 MagickNET.Version was added. That was after the release of 6.8.3.10 and before the release of 6.8.5.4. You can get the version of your dll with windows explorer from the tab 'details' in the properties of the file Magick.NET.dll.
May 14, 2013 at 7:53 AM
dlemstra wrote:
I did test with the image you uploaded to google. I am suspecting that you are still using the '6.8.3.10' version of Magick.NET.dll. In changeset 25941 MagickNET.Version was added. That was after the release of 6.8.3.10 and before the release of 6.8.5.4. You can get the version of your dll with windows explorer from the tab 'details' in the properties of the file Magick.NET.dll.
Sorry for late reply and Thanks a ton.... I downloaded the API versioned 6.8.5.4, it converts well with the new library.

Have a good day ahead.