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

exif tags not honored when applying image preprocessing chain #99

Open
jdale38 opened this issue Sep 27, 2019 · 7 comments
Open

exif tags not honored when applying image preprocessing chain #99

jdale38 opened this issue Sep 27, 2019 · 7 comments
Assignees
Labels

Comments

@jdale38
Copy link

jdale38 commented Sep 27, 2019

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

@yakirp yakirp self-assigned this Oct 8, 2019
@yakirp
Copy link
Contributor

yakirp commented Oct 8, 2019

Hey @jdale38,

Could you please add the steps to reproduce this issue?

Thanks
-yakir

@jdale38
Copy link
Author

jdale38 commented Oct 8, 2019

Steps:

  1. include Limit as a preprocessing step for MediaManager
  2. take a photo (using system camera) in portrait mode
  3. 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

@roeeba roeeba assigned nitzanj and unassigned yakirp Oct 20, 2019
@roeeba roeeba added the bug label Oct 20, 2019
@roeeba
Copy link

roeeba commented Oct 20, 2019

Hi @jdale38. We've forwarded this issue to our engineers to review. Updates to follow.

@jdale38
Copy link
Author

jdale38 commented Oct 24, 2019

@roeeba thank you! Let me know if there's any other info you and your team needs.

@roeeba
Copy link

roeeba commented Oct 29, 2019

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.

@dimaportenko
Copy link

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))

@aksjoshi1
Copy link

@dimaportenko Thank you for the update. We will have a look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants