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

[BUG] - Not all EXIF values are supported #408

Closed
Mouwrice opened this issue Jul 18, 2022 · 2 comments · Fixed by #409
Closed

[BUG] - Not all EXIF values are supported #408

Mouwrice opened this issue Jul 18, 2022 · 2 comments · Fixed by #409

Comments

@Mouwrice
Copy link
Contributor

Mouwrice commented Jul 18, 2022

  • Lib Version 4.3.0

Describe the bug
EXIF values not only define rotation but also mirroring, see EXIF values 2, 4, 5, 7:
image

But sadly that is not implemented in this library.

To Reproduce
Steps to reproduce the behavior:

  1. Open the app
  2. Select SAMPLE USING CROPIMAGEVIEW
  3. Choose an image that has EXIF value 2, 4, 5 or 7 (using the bottom left button) and see that they are orientated wrongly.

The exact images used are:
https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_2.jpg
https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_4.jpg
https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_5.jpg
https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_7.jpg

Try to crop an image that has an EXIF value of 2, 4, 5 or 7 and see that the image is in fact not correctly mirrored:
This is an image with EXIF value of 2
image

Expected behavior
Make use of these enums:
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface#ORIENTATION_FLIP_HORIZONTAL
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface#ORIENTATION_FLIP_VERTICAL
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface#ORIENTATION_TRANSPOSE
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface#ORIENTATION_TRANSVERSE

Which define what tranformations you need to apply to the image to get the correct orientation.

Media
You can test this out yourself by using the images provided in this repo:
https://github.com/recurser/exif-orientation-examples

Proposed solution
From a quick overview it seems that you should be able to pretty easily update the rotate function by exif value to also flip the image

/**
* Rotate the given image by given Exif value.<br></br>
* If no rotation is required the image will not be rotated.<br></br>
* New bitmap is created and the old one is recycled.
*/
fun rotateBitmapByExif(bitmap: Bitmap?, exif: ExifInterface): RotateBitmapResult {
val degrees: Int = when (
exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL
)
) {
ExifInterface.ORIENTATION_ROTATE_90 -> 90
ExifInterface.ORIENTATION_ROTATE_180 -> 180
ExifInterface.ORIENTATION_ROTATE_270 -> 270
else -> 0
}
return RotateBitmapResult(bitmap, degrees)

@Mouwrice Mouwrice added the bug label Jul 18, 2022
@Canato
Copy link
Member

Canato commented Jul 18, 2022

@Mouwrice this is great, please open a PR and let's fix this =)

@Mouwrice
Copy link
Contributor Author

@Mouwrice this is great, please open a PR and let's fix this =)

On it 💪

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 a pull request may close this issue.

2 participants