cloudinary_android icon indicating copy to clipboard operation
cloudinary_android copied to clipboard

exif tags not honored when applying image preprocessing chain

Open jdale38 opened this issue 5 years ago • 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

jdale38 avatar Sep 27 '19 22:09 jdale38

Hey @jdale38,

Could you please add the steps to reproduce this issue?

Thanks -yakir

yakirp avatar Oct 08 '19 12:10 yakirp

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

jdale38 avatar Oct 08 '19 20:10 jdale38

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

roeeba avatar Oct 20 '19 07:10 roeeba

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

jdale38 avatar Oct 24 '19 19:10 jdale38

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.

roeeba avatar Oct 29 '19 09:10 roeeba

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 avatar Aug 23 '22 15:08 dimaportenko

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

aksjoshi1 avatar Aug 23 '22 17:08 aksjoshi1