Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28093] TiAPI: Add properties "uprightWidth" and "uprightHeight" to Ti.Blob

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2020-09-10T13:24:02.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.2.0
ComponentsAndroid
Labelsandroid, blob, exif, iOS, image, jpeg, orientation
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-08-20T21:41:13.000+0000
Updated2020-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

FileDateSize
DownloadImageBlobTest.js2020-08-21T00:12:10.000+00002904

Comments

  1. Joshua Quick 2020-08-21

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/11936
  2. Michael Gangolf 2020-08-21

    [~jquick] Awesome! Will try that in my app later today
  3. Michael Gangolf 2020-08-21

    Merged it into my custom 9_1_x and works fine! Now I now if I have to switch my values or not (y)
  4. Samir Mohammed 2020-08-26

    FR Passed, Waiting on Jenkins build and 9_3_X build.
  5. Samir Mohammed 2020-09-10

    *Closing ticket*. Improvement verified in SDK version 9.2.0.v20200908050955, and 9.3.0.v20200908051946. *Test and other information can be found at:* https://github.com/appcelerator/titanium_mobile/pull/11936

JSON Source