-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add autorotate flag #51
Conversation
This looks good, I'll try to review it soon. |
Have you had a chance to review this yet? |
I've just merged from master so this is again free of any conflicts. |
The code looks good to me, but when testing it on a file I got a wrong, but different rotation. I was able to resolve this by just setting the Exif rotation byte to 0 (deleting the Exif chunk would also work). However, this approach would not work when a perfect transformation is not possible. Trying to do a perfect transformation should also be the default as a not perfect transformation would result in cut off pixels. I will try to modify the code such that the file is rotated correctly and the exif chunk is preserved when a perfect transformation is not possible. Thanks for your work by the way, I was too busy with classes to put a lot work into this project for a while now. |
Oops, perhaps some of my map values are wrong! Could you attach the file you tried? I'm sure I tested all the values, I was using this example set: https://github.com/recurser/exif-orientation-examples My use case is for the web where orientation values are ignored by all browsers, so actually rotating the data is necessary and retaining the orientation flag is useless. (Plus, imperfect images with orientation values are extremely rare outside of test cases). |
I would suggest |
I've changed the behaviour to be perfect by default and to force rotation via |
I think the problem that caused the wrong rotation in my tests is that your code transforms the image data in such a way that the image is rotated correctly, but does not modify or remove the EXIF data which causes it to be rotated in a different way again. |
Odd, it's not supposed to let you use -autorotate with also specifying -strip, which enforces the removal of the orientation flag. |
Looks like your code requires -strip: https://github.com/fhanau/Efficient-Compression-Tool/pull/51/files#diff-7ec3c68a81efff79b6ca22ac1f1eabbaR605 |
Yeah, is that not working for you? I just tried it on that image, it bails out if I don't specify -strip. |
What I meant is that the only way to enable auto rotation is '-autorotate(-strict) -strip', which changes the rotation from right to wrong when viewed with software that does not ignore rotation values. |
Sorry, I'm still a bit confused. What is the incorrect output you're seeing? |
Ok, so I hadn't tested the new version. With this commit, autorotate=force seems to work properly, but using -autorotate on a file that can't be transformed perfectly causes it to have a changed rotation (I think that it shouldn't be like that as the autorotate flag indicates that a right rotation should be preserved). I think this can be fixed by just not stripping the EXIF data in that case. |
Ok, both versions of autorotate should lead to the right rotation now. Thank you for your work. |
Awesome, thanks heaps for merging that :) |
This PR adds an -autorotate flag to automatically transform JPEGs according to their Exif orientation. The -autorotate flag requires -strip. If --strict is also provided, transformation will only be done if it is "perfect", otherwise untransformable blocks will be trimmed (very rare).
Disclaimer: I'm not a C programmer and don't know what I'm doing.
Keen to hear any feedback and happy to make any changes requested.
Fixes #47