Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27872] Android: Blob imageAsX() methods ignore EXIF orientation if not wrapping a file

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2020-08-11T13:13:50.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.1.0
ComponentsAndroid
Labelsandroid, blob, exif, jpeg, orientation
ReporterSamir Mohammed
AssigneeJoshua Quick
Created2020-04-29T16:21:18.000+0000
Updated2020-08-11T13:13:50.000+0000

Description

*Summary:* When a Titanium blob references a non-file type, such as a byte buffer or "content://" URL, then the blob's imageAs*() methods will ignore a JPEG's EXIF orientation setting. This affects the following methods: * Blob.imageAsCropped() * Blob.imageAsResized() * Blob.imageAsThumbnail() * Blob.imageWithAlpha() * Blob.imageWithRoundedCorner() * Blob.imageWithTransparentBorder() *Steps to reproduce:*

Build the attached [^DownloadImageBlobTest.js] on Android.

Tap on the "Download" button. (Requires Internet access.)

Tap on "JPEG - EXIF Rotate 90" in option dialog.

Notice that the displayed resized image is not upright. (This is the bug.

Do the same with all of the other "EXIF" options in the dialog. They all have this issue.

Attachments

FileDateSize
DownloadImageBlobTest.js2020-05-02T01:07:16.000+00002688

Comments

  1. Joshua Quick 2020-04-29

    It's an issue with blobs that do *not* wrap a file system path. That is, blobs which wrap a "content://" URL (like in above test case) or when the blobs wraps an in-memory image. *Solution:* In our TiBlob.java code, we have method calls to TiImageHelper.getOrientation() which fetch the EXIF orientation from a JPEG. Instead of passing a file path to it, we should pass an InputStream to it instead. https://github.com/jquick-axway/titanium_mobile/blob/master/android/titanium/src/java/org/appcelerator/titanium/TiBlob.java
  2. Joshua Quick 2020-05-02

    Below is [~smohammed]'s original ticket summary. Th below can reproduce this issue when taking a camera shot on a Pixel XL device and then calling imageAsResized(). Not all devices can reproduce it this way though since some camera will always save the photo in the upright position... and some won't and will write the orientation to the JPEG's EXIF data instead. *+Test Case:+* *index.js*
       _.delay(function() {
       	Titanium.Media.showCamera({
       		success: function(e) {
       			var start = new Date().getTime();
       			var blob = e.media;
       			var w = e.media.width;
       			var h = e.media.height;
       			var r = h / w;
       			w = 350;
       			h = 300;
       			blob = blob.imageAsResized(w, h);
       			$.img.image = blob;
       			var end = new Date().getTime();
       			console.log(end - start);
        
       			console.log(e.media.width, e.media.height);
       			console.log(blob.width, blob.height);
       		},
       		cancel: function() {},
       		error: function(error) {},
       		mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO]
       	});
       }, 4000);
        
       $.index.open();
       
    *index.xml*
       <Alloy>
       	<Window class="container">
       		<ImageView id="img"></ImageView>
       	</Window>
       </Alloy>
       
    *Test Steps*

    Download SDK version 9.0.2.GA

    Create an alloy application

    Copy the test case above

    Make sure camera permissions are enabled

    Run the application on a Pixel XL

    Take a picture in portrait mode

    Check log for the orientation (width, height)

    *Expected result* Console should log the correct orientation (350, 300) in this case *Actual result* The orientation is flipped and displayed as (300, 350)
  3. Joshua Quick 2020-05-02

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/11679
  4. Satyam Sekhri 2020-05-20

    FR Passed. Waiting for Jenkins build
  5. Christopher Williams 2020-05-21

    merged to master for 9.1.0 target
  6. Samir Mohammed 2020-08-11

    *Closing ticket*. Improvement verified in SDK version 9.1.0.v20200810120239. *Test and other information can be found at:* https://github.com/appcelerator/titanium_mobile/pull/11679

JSON Source