This project has moved. For the latest updates, please go here.

Crop failing on image

Nov 21, 2015 at 6:56 AM
[TEXT](http://kitt.us/photo.png

Crop has been working perfectly for a long time. But on this image, it resets the image to 1x1 pixel. I can't figure out why this is not working.

I suspect it's something specific to this image, but I can't see the problem. The x,y,width,height are not relevant, pick a value. Whatever you put, the resulting image is 1x1 pixel.

Here is my code:
        using (MagickImage img = new MagickImage(strFileName))
        {
            img.Crop(new MagickGeometry(x, y, width, height));
            img.Write(strCrop);
        }
I have also tried this.
        using (MagickImage img = new MagickImage(strFileName))
        {
            img.Crop(new MagickGeometry(x, y, width, height));
            img.RePage();
            img.Write(strCrop);
        }
Coordinator
Nov 21, 2015 at 8:58 AM
The problem is most likely a mistake in the x,y width,height arguments. I think you are cropping the image to an area larger than the image is.
Nov 21, 2015 at 9:33 PM

No, sorry, it’s not. Take the image I attached to the problem ticket. Try this code. Resulting image is 1x1

string strFileName = @"C:\Temp\Photo.png";

string strCrop = Path.GetDirectoryName(strFileName) + @"\" + Guid.NewGuid().ToString() + Path.GetExtension(strFileName);

using (MagickImage img = new MagickImage(strFileName))

{

img.Crop(new MagickGeometry(10, 10, img.Width - 20, img.Height - 20));

img.RePage();

img.Write(strCrop);

}

Coordinator
Nov 21, 2015 at 10:32 PM
It seems that your input image has a really strange Page value: 2021x2373+690+816. Doing a RePage before the crop seems to fix this issue.
Nov 22, 2015 at 4:23 AM

That fixed it! Thanks!