I have a problem. I try to crop an image with a resolution of 6000x4000 pixel but it t takes the wrong part of the picture. The Picture is market with am exif orientation attribute with the value 8. Can鈥檛 find a way to crop the right part.
Using the latest nugget package.
Hi @SergeBerwert Can you please fill in the issue template properly so I can actually investigate your issue.
using (var factory = new ImageFactory(true))
{
factory.Load(File.ReadAllBytes("C:\\Work\\ImageProcessor\\wikimedia-43251641.jpg"));
var area = new Rectangle(439,939, 2778, 2778);
factory.Crop(area).Format(new JpegFormat() {Quality = 80}).Save("C:\\Work\\ImageProcessor\\output.jpg");
}
Source Picture : https://upload.wikimedia.org/wikipedia/commons/0/07/Jos%C3%A9_Mar%C3%ADa_Buljubasich.JPG
the coordinates target the face
After studying the exif orientation flag a little bit more I found the problem. The problem was, to crop the right region, I not only had to turn the x and y coordinates, I also had to calculate with a different offset. Instead calculating x from zero up, I had to calculate from max width down.
The second problem was I tried to use AutoRotate but it had no effect because I instantiated the factory with prevent exif information flag. Then AutoRotate had no effect. For this case I would suggest throwing an exception.
Love the Library!
Hi @SergeBerwert
Good analysis!
Yeah that's exactly what's happening. Theoretically we could rotate each point on the rectangle to go with the EXIF orientation and then crop so you wouldn't have to do the maths. I'll have a look when I can, all the bits to do it are in the library already.
I'm not sure about throwing an exception. It would be good for education but I don't want to be in a situation where I break some sort of automation process out there in the wild. I'll have a think.
Also.... Thanks!
Hi @SergeBerwert
You couldn't do me a favor and provide me with a test image and expected output could you? I'd like to have a crack at enhancing Crop to deal with this situation.
Cheers!
Hi @JimBobSquarePants
you can take the example from above
https://upload.wikimedia.org/wikipedia/commons/0/07/Jos%C3%A9_Mar%C3%ADa_Buljubasich.JPG
Cutting Left = 939, Top = 439, High = 2778, Width = 2778, should cut out the head.
Brilliant Thanks!
Hey @SergeBerwert I've just pushed the fix for this and should be able to get a release out very soon.