exif tags not honored when applying image preprocessing chain
jdale38 opened this issue · 7 comments
It looks like BitmapDecoder
used in ImageProcessChain
does not rotate images with the included exif orientation tags on a photo. Not including any preprocessing chains for photo uploads resolves this issue.
A possible solution -> applying Matrix#postRotate()
with a newly created bitmap during bitmap decoding (https://github.com/cloudinary/cloudinary_android/blob/master/lib/src/main/java/com/cloudinary/android/preprocess/BitmapDecoder.java#L82).
Device info:
Android 9
Pixel 2 emulator
SDK info:
1.26.0
Steps:
- include
Limit
as a preprocessing step forMediaManager
- take a photo (using system camera) in portrait mode
- upload photo taken from step 2 via
MediaManager.upload(portraitPhotoUri).preprocess(limit).dispatch()
Let me know if there's anything else I can shed some light on.
Thanks,
Josh
Hi @jdale38. We've forwarded this issue to our engineers to review. Updates to follow.
Hi @jdale38. We've tried to recreate the issue (tested on real device and the emulator as per their spec; pixel 2, android 9) and we didn't see an issue with the rotation of the image. EXIF data is indeed not retained (seems like a minor issue, which we'll investigate) but the rotation is still handled correctly automatically.
Can you please let us know how are you getting the URI to the picture itself? code snippets would help greatly, so we can try and recreate the issue.
You can also refer to the sample app in the android repo - we use preprocessing there and the orientation is correct.
here is how I solved missing rotation
public int getExifAngle(String filePath) {
int angle = 0;
try {
ExifInterface exif = new ExifInterface(filePath);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
Log.d("EXIF", "Exif: " + orientation);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
angle = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
angle = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
angle = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return angle;
}
// ------
....
uploadRequest.preprocess(
ImagePreprocessChain.limitDimensionsChain(MAX_IMAGE_DIMENSION, MAX_IMAGE_DIMENSION)
.addStep(new DimensionsValidator(10, 10, MAX_IMAGE_DIMENSION, MAX_IMAGE_DIMENSION))
.addStep(new Rotate(angle))
.saveWith(new BitmapEncoder(BitmapEncoder.Format.JPEG, 80))
@dimaportenko Thank you for the update. We will have a look into it.