While trying to improve PerceptualHash performance, I came across a couple errors. With very large images, PerceptualHash takes forever to compute. I'm submitting the errors as separate issues with the same code sample.
AdaptiveResize, as seen below, internally disposes the image when it is called. I've tried it on several images.
![Image](http://it.yoyowall.com/wallpaper/camouflage-f-22.html)
```
public static ImageMagick.PerceptualHash PHash(this FileInfo file, int imageSizeConstraint = 5000)
{
if (imageSizeConstraint < 1000)
imageSizeConstraint = 1000;
using (MagickImage image = new MagickImage(file.FullName))
{
if (image.Width > imageSizeConstraint || image.Height > imageSizeConstraint)
{
double percent;
if (image.Width > image.Height)
percent = imageSizeConstraint / (double)image.Width;
else
percent = imageSizeConstraint / (double)image.Height;
Percentage p = new Percentage(percent);
if (percent < 0.5)
image.AdaptiveResize(new MagickGeometry(p, p));
else
image.Resize(p);
}
return image.PerceptualHash();
}
}
```
Comments: Sorry, the image link is broken, but I think the bug may show up on any image. If not I'll try to get you an image to test against.
AdaptiveResize, as seen below, internally disposes the image when it is called. I've tried it on several images.
![Image](http://it.yoyowall.com/wallpaper/camouflage-f-22.html)
```
public static ImageMagick.PerceptualHash PHash(this FileInfo file, int imageSizeConstraint = 5000)
{
if (imageSizeConstraint < 1000)
imageSizeConstraint = 1000;
using (MagickImage image = new MagickImage(file.FullName))
{
if (image.Width > imageSizeConstraint || image.Height > imageSizeConstraint)
{
double percent;
if (image.Width > image.Height)
percent = imageSizeConstraint / (double)image.Width;
else
percent = imageSizeConstraint / (double)image.Height;
Percentage p = new Percentage(percent);
if (percent < 0.5)
image.AdaptiveResize(new MagickGeometry(p, p));
else
image.Resize(p);
}
return image.PerceptualHash();
}
}
```
Comments: Sorry, the image link is broken, but I think the bug may show up on any image. If not I'll try to get you an image to test against.