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

More than one crop results in a 1x1 (blank) image

May 11, 2015 at 2:41 PM
I know it's not the most ideal but for code simplicity, I do 2 crops on the same image. It's actually a crop, then a scale, then another crop, but I got rid of the scale in the middle and was still able to reproduce the problem.

Using this image, if I do the following:
_magickImage.Crop(new MagickGeometry(1340, 47, 924, 1144));
_magickImage.Crop(new MagickGeometry(0, 0, 100, 100));
After the first call, I can see in the debugger that I now have a 924x1144 image. But no matter what dimensions I put in the second Crop call, it turns out a 1x1 jpeg. How do I get around this?
Coordinator
May 11, 2015 at 3:08 PM
It seems you have to reset the 'page' of the image before you do the next crop. You can find some information about that here: http://www.imagemagick.org/Usage/crop/#crop_repage. Your code would become this:
_magickImage.Crop(new MagickGeometry(1340, 47, 924, 1144));
_magickImage.RePage();
_magickImage.Crop(new MagickGeometry(0, 0, 100, 100));
May 11, 2015 at 3:22 PM
Awesome, I was hoping it would be an easy fix! I don't know if I would've ever found that on my own. I was even going to ask if it's recommended to do that after every crop but I see that link you referenced says exactly that. Thanks again!
May 12, 2015 at 3:24 PM
Brilliant, thanks! I encountered a similar issue last night with cropping resulting in a 1x1 pixel output but I worked around it by saving the image and reloading it before performing the crop. RePage() looks like a much cleaner solution as the volume of very small images I want to process in a short amount of time should benefit from not requiring the I/O operations for saving and reading files.
Coordinator
May 12, 2015 at 3:34 PM
I will update the Intellisense help to include a remark about using RePage after a Crop.