[TIMOB-28093] TiAPI: Add properties "uprightWidth" and "uprightHeight" to Ti.Blob
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2020-09-10T13:24:02.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 9.2.0 |
Components | Android |
Labels | android, blob, exif, iOS, image, jpeg, orientation |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2020-08-20T21:41:13.000+0000 |
Updated | 2020-09-10T13:24:02.000+0000 |
Description
*Summary:*
When a Titanium
Blob
wraps an image, its "width" and "height" properties provide the "decoded" image's dimensions. Unfortunately, Android's native image loading APIs ignore a JPEG's EXIF orientation, meaning the image is loaded as-is (no rotation applied). While our ImageView
and other APIs will correctly handle the EXIF orientation, the blob's "width" and "height" is for the unrotated image which makes it difficult to do manual layouts (ex: calculate letterbox scaling).
*Proposed Solution:*
Add the following properties to Titanium Blob
:
* uprightWidth
* uprightHeight
The above properties will return what the image width and height should be when a JPEG's EXIF orientation is applied onscreen. If the image is not a JPEG or the JPEG has no EXIF orientation, then these properties will return the same values as "width" and "height".
And since iOS loads images in the upright positions, the above properties will always return the same values as "width" and "height".
*Use-Case:*
Developers need the image's actual width and height to do things like letterbox scaling. For example...
var scale = Math.min(
Ti.UI.convertUnits(window.size.width, Ti.UI.UNIT_PX) / imageBlob.width,
Ti.UI.convertUnits(window.size.height, Ti.UI.UNIT_PX) / imageBlob.height);
imageView.image = imageBlob;
imageView.width = imageBlob.width * scale;
imageView.height = imageBlob.height * scale;
If the JPEG is loaded sideways (ie: its EXIF orientation is ignored), then the above will scale the image wrong.
*Note:*
This is an interim solution. A better solution would be to completely refactor Titanium's image loading code and decode the image in the upright position (pre-rotated). This will be a huge undertaking that is best done in a major Titanium release version. But when we do this, Android's "uprightWidth" and "uprightHeight" properties will match "width" and "height" just like iOS.
Attachments
File | Date | Size |
---|---|---|
DownloadImageBlobTest.js | 2020-08-21T00:12:10.000+0000 | 2904 |
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11936
[~jquick] Awesome! Will try that in my app later today
Merged it into my custom 9_1_x and works fine! Now I now if I have to switch my values or not (y)
FR Passed, Waiting on Jenkins build and 9_3_X build.
*Closing ticket*. Improvement verified in SDK version
9.2.0.v20200908050955
, and9.3.0.v20200908051946
. *Test and other information can be found at:* https://github.com/appcelerator/titanium_mobile/pull/11936