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

Respect EXIF information while decompressing images. #9905

Merged
merged 2 commits into from
Jul 18, 2019

Conversation

chinmaygarde
Copy link
Member

Adds a unit-test asserting this behavior.

Adds a unit-test asserting this behavior.
@chinmaygarde
Copy link
Member Author

Re-fixes flutter/flutter#10895

@chinmaygarde
Copy link
Member Author

LUCI failure is a red-herring. The last entry is actually a hot-fix patch. Landing.

@chinmaygarde chinmaygarde merged commit fd2cb81 into flutter:master Jul 18, 2019
@chinmaygarde chinmaygarde deleted the read_exif branch July 18, 2019 02:14
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 18, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 19, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Jul 19, 2019
flutter/engine@f348270...5467f6f

git log f348270..5467f6f --no-merges --oneline
5467f6f Roll src/third_party/skia bf1d4effe171..19547c91b983 (4 commits) (flutter/engine#9942)
15797da Roll src/third_party/skia de71a74fc40e..bf1d4effe171 (5 commits) (flutter/engine#9940)
db0839a Copy over fuchsia dev key from buildroot (flutter/engine#9936)
934e225 Build fuchsia artifacts from the engine (flutter/engine#9933)
9e04776 Update the exception thrown for invalid data in the codec test (flutter/engine#9929)
678ce2e Fix reentrancy handling in SingleFrameCodec (flutter/engine#9931)
9bb1b89 Update libcxx & libcxxabi to HEAD in prep for compiler upgrade. (flutter/engine#9906)
cad5cc2 Roll src/third_party/skia 3e6aa9f52839..de71a74fc40e (11 commits) (flutter/engine#9930)
5ed71f1 Handle decompressed images in InstantiateImageCodec (flutter/engine#9901)
ad5ae0f Update Buildroot Version (flutter/engine#9927)
f20e935 Fix failure of the onReportTimings window hook test (flutter/engine#9923)
eaf1f33 Don't try to use unset assets_dir setting (flutter/engine#9924)
ae14f04 Add the isMultiline semantics flag to values (flutter/engine#9894)
cf3fd6d Roll src/third_party/skia 83cfe4fa24d9..3e6aa9f52839 (6 commits) (flutter/engine#9921)
cf40c24 Removed unused method. (flutter/engine#9919)
7bd8fc3 Roll fuchsia/sdk/core/mac-amd64 from GcUOj20BDDGW4Sz4cnsI4_Lf9qte_6OCgQBmDQLnGNcC to xNAaLqZJk8Bkz00BaHGzE8hCpiohggO7KabM3g2wdsQC (flutter/engine#9918)
68ae872 Made the persistent cache's directory a const pointer. (flutter/engine#9815)
8720043 Roll src/third_party/skia a2e7d5e2b63c..83cfe4fa24d9 (3 commits) (flutter/engine#9916)
b28ccd8 Roll fuchsia/sdk/core/mac-amd64 from 9XAYIkrdh9JQjy22gyni7VbK2yYurszww1k9zRQ_jU8C to GcUOj20BDDGW4Sz4cnsI4_Lf9qte_6OCgQBmDQLnGNcC (flutter/engine#9915)
89a9a95 Roll fuchsia/sdk/core/mac-amd64 from lXCuLh2YGWM641A5Io3ASt3Uy70e_YGRKFLf46new08C to 9XAYIkrdh9JQjy22gyni7VbK2yYurszww1k9zRQ_jU8C (flutter/engine#9911)
c8f35b9 Roll src/third_party/skia ea6da6909624..a2e7d5e2b63c (3 commits) (flutter/engine#9910)
8704d61 Roll src/third_party/dart 6bf1f8e280..63120303a7 (4 commits)
866d057 Roll src/third_party/dart 0506882b37..6bf1f8e280 (9 commits)
7289354 Roll src/third_party/dart 8cb7e4c237..0506882b37 (3 commits)
d84b938 Roll src/third_party/dart 41d3971e83..8cb7e4c237 (2 commits)
52b226c Roll src/third_party/dart 2b3336b51e..41d3971e83 (3 commits)
cf4129b Roll fuchsia/sdk/core/mac-amd64 from 0NcHg3_AYcxrkseoO6xmXrQ-GZ82gy8CE5NU-SDJq_QC to lXCuLh2YGWM641A5Io3ASt3Uy70e_YGRKFLf46new08C (flutter/engine#9908)
c2133b4 Roll src/third_party/skia d7639aff1001..ea6da6909624 (7 commits) (flutter/engine#9907)
ca91c66 Roll fuchsia/sdk/core/mac-amd64 from JDPk4JFZX16IXpzzjQH5KFf0vRALbOtJYiMHCqFLFOQC to 0NcHg3_AYcxrkseoO6xmXrQ-GZ82gy8CE5NU-SDJq_QC (flutter/engine#9904)
fd2cb81 Respect EXIF information while decompressing images. (flutter/engine#9905)
dd06cda Fix justify for RTL paragraphs. (flutter/engine#9859)
be3e2ed Fix fuchsia license detection (flutter/engine#9857)
b7b791b In a single frame codec, release the compressed image buffer after giving it to the decoder (flutter/engine#9825)
1af19ae Roll fuchsia/sdk/core/mac-amd64 from PHtpiJGexJFgd7sgPTUbFphKES09fzotmtrO2kTHI08C to JDPk4JFZX16IXpzzjQH5KFf0vRALbOtJYiMHCqFLFOQC (flutter/engine#9892)
5d9f7b1 Log dlopen errors only in debug mode (flutter/engine#9890)
8f060b9 Add clang version to Info.plist (flutter/engine#9873)
0fcf3b3 Roll src/third_party/skia e574f1e409aa..d7639aff1001 (16 commits) (flutter/engine#9889)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff ([email protected]), and stop
the roller if necessary.
...
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
flutter/engine@f348270...5467f6f

git log f348270..5467f6f --no-merges --oneline
5467f6f Roll src/third_party/skia bf1d4effe171..19547c91b983 (4 commits) (flutter/engine#9942)
15797da Roll src/third_party/skia de71a74fc40e..bf1d4effe171 (5 commits) (flutter/engine#9940)
db0839a Copy over fuchsia dev key from buildroot (flutter/engine#9936)
934e225 Build fuchsia artifacts from the engine (flutter/engine#9933)
9e04776 Update the exception thrown for invalid data in the codec test (flutter/engine#9929)
678ce2e Fix reentrancy handling in SingleFrameCodec (flutter/engine#9931)
9bb1b89 Update libcxx & libcxxabi to HEAD in prep for compiler upgrade. (flutter/engine#9906)
cad5cc2 Roll src/third_party/skia 3e6aa9f52839..de71a74fc40e (11 commits) (flutter/engine#9930)
5ed71f1 Handle decompressed images in InstantiateImageCodec (flutter/engine#9901)
ad5ae0f Update Buildroot Version (flutter/engine#9927)
f20e935 Fix failure of the onReportTimings window hook test (flutter/engine#9923)
eaf1f33 Don&flutter#39;t try to use unset assets_dir setting (flutter/engine#9924)
ae14f04 Add the isMultiline semantics flag to values (flutter/engine#9894)
cf3fd6d Roll src/third_party/skia 83cfe4fa24d9..3e6aa9f52839 (6 commits) (flutter/engine#9921)
cf40c24 Removed unused method. (flutter/engine#9919)
7bd8fc3 Roll fuchsia/sdk/core/mac-amd64 from GcUOj20BDDGW4Sz4cnsI4_Lf9qte_6OCgQBmDQLnGNcC to xNAaLqZJk8Bkz00BaHGzE8hCpiohggO7KabM3g2wdsQC (flutter/engine#9918)
68ae872 Made the persistent cache&flutter#39;s directory a const pointer. (flutter/engine#9815)
8720043 Roll src/third_party/skia a2e7d5e2b63c..83cfe4fa24d9 (3 commits) (flutter/engine#9916)
b28ccd8 Roll fuchsia/sdk/core/mac-amd64 from 9XAYIkrdh9JQjy22gyni7VbK2yYurszww1k9zRQ_jU8C to GcUOj20BDDGW4Sz4cnsI4_Lf9qte_6OCgQBmDQLnGNcC (flutter/engine#9915)
89a9a95 Roll fuchsia/sdk/core/mac-amd64 from lXCuLh2YGWM641A5Io3ASt3Uy70e_YGRKFLf46new08C to 9XAYIkrdh9JQjy22gyni7VbK2yYurszww1k9zRQ_jU8C (flutter/engine#9911)
c8f35b9 Roll src/third_party/skia ea6da6909624..a2e7d5e2b63c (3 commits) (flutter/engine#9910)
8704d61 Roll src/third_party/dart 6bf1f8e280..63120303a7 (4 commits)
866d057 Roll src/third_party/dart 0506882b37..6bf1f8e280 (9 commits)
7289354 Roll src/third_party/dart 8cb7e4c237..0506882b37 (3 commits)
d84b938 Roll src/third_party/dart 41d3971e83..8cb7e4c237 (2 commits)
52b226c Roll src/third_party/dart 2b3336b51e..41d3971e83 (3 commits)
cf4129b Roll fuchsia/sdk/core/mac-amd64 from 0NcHg3_AYcxrkseoO6xmXrQ-GZ82gy8CE5NU-SDJq_QC to lXCuLh2YGWM641A5Io3ASt3Uy70e_YGRKFLf46new08C (flutter/engine#9908)
c2133b4 Roll src/third_party/skia d7639aff1001..ea6da6909624 (7 commits) (flutter/engine#9907)
ca91c66 Roll fuchsia/sdk/core/mac-amd64 from JDPk4JFZX16IXpzzjQH5KFf0vRALbOtJYiMHCqFLFOQC to 0NcHg3_AYcxrkseoO6xmXrQ-GZ82gy8CE5NU-SDJq_QC (flutter/engine#9904)
fd2cb81 Respect EXIF information while decompressing images. (flutter/engine#9905)
dd06cda Fix justify for RTL paragraphs. (flutter/engine#9859)
be3e2ed Fix fuchsia license detection (flutter/engine#9857)
b7b791b In a single frame codec, release the compressed image buffer after giving it to the decoder (flutter/engine#9825)
1af19ae Roll fuchsia/sdk/core/mac-amd64 from PHtpiJGexJFgd7sgPTUbFphKES09fzotmtrO2kTHI08C to JDPk4JFZX16IXpzzjQH5KFf0vRALbOtJYiMHCqFLFOQC (flutter/engine#9892)
5d9f7b1 Log dlopen errors only in debug mode (flutter/engine#9890)
8f060b9 Add clang version to Info.plist (flutter/engine#9873)
0fcf3b3 Roll src/third_party/skia e574f1e409aa..d7639aff1001 (16 commits) (flutter/engine#9889)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff ([email protected]), and stop
the roller if necessary.
...
@matte5031
Copy link

@chinmaygarde chinmaygarde I have this issue on iOS where most images are rotated 90 degrees, happens in ios simulator aswell as physical device.
Using flutter beta channel and latest image_picker plugin. Should this be fixed now or why am i seeing this issue? Thanks

@chinmaygarde
Copy link
Member Author

If you are on the latest beta, this commit should be have rolled in there. Can you pull the latest beta and try again? Or, ensure that bin/internal/engine.version contains a SHA that is past the commit in the PR. Or, switch to the dev channel and try again. If you still see an issue, please file a bug with a reduced test case. It may be (but is unlikely to be) an unrelated issue.

@matte5031
Copy link

matte5031 commented Aug 9, 2019

@chinmaygarde Thanks for reaching out. I tried flutter upgrade and this was the output:

Already up to date.

Upgrading engine...

Flutter 1.8.3 • channel beta • https://github.com/flutter/flutter.git
Framework • revision e4ebcdf (13 days ago) • 2019-07-27 11:48:24 -0700
Engine • revision 38ac5f3
Tools • Dart 2.5.0 (build 2.5.0-dev.1.0 0ca1582)

I checked the exif information on the images that are rotated, and they actually say they should be 90 degrees rotated (the ones i checked have been taken in portrait mode). The ones that look fine from my iphone 6 are the screenshots, they miss exif information but are not rotated.

A bit confused why the exif should say 90 degrees rotated because they should not be rotated. The same happens in the simulator. I tried to take the same image and upload it to facebook and then check the exif information, it turns out that the rotation part has been wiped and that it looks good there.

Sorry for a lot of text just trying to give as much information as possible. From theese testings is seems like I should try to remove the exif data from the image in flutter if possible because it seem to add rotation to it.

@chinmaygarde
Copy link
Member Author

If EXIF data says the image should be rotated, then it seems like the engine is working as intended. It is possible that the upload process on Facebook clobbers EXIF information. Even GitHub seems to ignore EXIF information while displaying the image.

Beyond fixing the incorrect exif information, I am not sure what to suggest. You could maybe file a feature request that says something like "Add an optional flag on image decoders to ignore EXIF information". You could then apply any transformation you wanted manually. Or not, if you want want bug-for-bug compatibility with certain image handlers.

@matte5031
Copy link

@chinmaygarde Okay thanks for the info. Out of curiousity, there are some default images in the ios, simulator, have you tried using the image picker to retrieve them and show them? some of them are rotated for me, curious if that is as expected or if all the images are shown correctly for other people.

@matte5031
Copy link

@chinmaygarde Actually find that many other people still having this issue. Refering to flutter/flutter#35334

@matte5031
Copy link

matte5031 commented Aug 10, 2019

@chinmaygarde I would just like to let you know that I found code that someone had created that could be used to handle this. It's not optimal but, this is no longer an issue for me. The code that I use looks like this:

`Future<File> rotateAndCompressAndSaveImage(File image) async {
int rotate = 0;
List<int> imageBytes = await image.readAsBytes();
Map<String, IfdTag> exifData = await readExifFromBytes(imageBytes);

if (exifData != null &&
    exifData.isNotEmpty &&
    exifData.containsKey("Image Orientation")) {
  IfdTag orientation = exifData["Image Orientation"];
  int orientationValue = orientation.values[0];

  if (orientationValue == 3) {
    rotate = 180;
  }

  if (orientationValue == 6) {
    rotate = -90;
  }

  if (orientationValue == 8) {
    rotate = 90;
  }
}

List<int> result = await FlutterImageCompress.compressWithList(imageBytes,
    quality: 100, rotate: rotate);

await image.writeAsBytes(result);

return image;
}`

@worawutt
Copy link

@chinmaygarde I would just like to let you know that I found code that someone had created that could be used to handle this. It's not optimal but, this is no longer an issue for me. The code that I use looks like this:

`Future<File> rotateAndCompressAndSaveImage(File image) async {
int rotate = 0;
List<int> imageBytes = await image.readAsBytes();
Map<String, IfdTag> exifData = await readExifFromBytes(imageBytes);

if (exifData != null &&
    exifData.isNotEmpty &&
    exifData.containsKey("Image Orientation")) {
  IfdTag orientation = exifData["Image Orientation"];
  int orientationValue = orientation.values[0];

  if (orientationValue == 3) {
    rotate = 180;
  }

  if (orientationValue == 6) {
    rotate = -90;
  }

  if (orientationValue == 8) {
    rotate = 90;
  }
}

List<int> result = await FlutterImageCompress.compressWithList(imageBytes,
    quality: 100, rotate: rotate);

await image.writeAsBytes(result);

return image;
}`

I test the code and found issue on android that portrait image will rotate -90˚.
I put an 'if' clause for iOS only for orientationValue == 6 and 8, the issue has gone.
// image_picker: 0.6.1+2

if (Platform.isIOS) {
  if (orientationValue == 6) {
    rotate = -90;
  }
  if (orientationValue == 8) {
    rotate = 90;
  }
}

I did test 0.6.1+3, when use parameters max_width and max_height, the image does not keep aspect ratio. so I back to 0.6.1+2 and use your code with an if condition.

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

Successfully merging this pull request may close these issues.

5 participants