Skip to content
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

AutoOrient to automatically fix orientation of images based on EXIF orientation flag #140

Closed
wants to merge 3 commits into from

Conversation

LeoAdamek
Copy link

This PR adds a new func to the bimg.Image type AutoOrient which will perform the required processes to correct the orientation of the image based on the EXIF orientation flag.

Copy link
Owner

@h2non h2non left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, take a look to my comments.

options.Flip = true
break
case 3:
options.Rotate = 180
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might consider using bimg.Angle here. See:
https://github.com/h2non/bimg/blob/master/options.go#L57-L74

@@ -155,6 +157,52 @@ func (i *Image) Flop() ([]byte, error) {
return i.Process(options)
}

// AutoOrient automatically flips/flops/rotates the image
// based on EXIF Orientation
func (i *Image) AutoOrient() ([]byte, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this capability aims to be implemented here:
https://github.com/h2non/bimg/blob/master/resize.go#L501-L537

I think this would be redundant. Perhaps makes more sense to merge code into the existent code.

@LeoAdamek
Copy link
Author

@h2non Thanks for the feedback, didn't see this func because its not exported.

Agreed there may be some redundancy here, but would it not make sense for this feature to behave in the same way the other "convenience" methods?

Is your suggestion that there be an AutoOrient bool property on the Options struct which will run the calculateRotationAndFlip function from resize.go ?

-Leo

@h2non
Copy link
Owner

h2non commented Mar 16, 2017

Is your suggestion that there be an AutoOrient bool property on the Options struct which will run the calculateRotationAndFlip function from resize.go ?

The intended default behavior is to process images with auto orientation, unless you explicitly want to disable that behavior via:
https://github.com/h2non/bimg/blob/master/options.go#L201

I agree about exposing that capability as part of the public API.
Perhaps we should simply converge both functions into a single one which is also exported.

@LeoAdamek
Copy link
Author

In which case, would an AutoOrient function just pass an empty Options{} struct to resize and return that?

My my use case, I need to have the image correctly oriented for later processing, including being able to get the dimensions with that orientation applied.

@h2non
Copy link
Owner

h2non commented Sep 10, 2017

This should be already fixed by #183. Feature is now available in bimg v1.0.11+.

@h2non h2non closed this Sep 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants