Issue description
Looking for a cross-platform way to create image thumbnail files asynchronously. Titanium is able to read an image file asynchronously into a buffer and then a blob. If we assign that blob to the image property of an ImageView, it displays as I expect. However, the blob is not recognised as an image by any of the Ti.Blob.image* methods. The blob has a mime type of "application/octet-stream" and a height and width of 0. Meanwhile Android is able to get height and width properly.
Steps to reproduce
Launch sample app. You can see that the fishImage ImageView loads its image directly from a file path in its "image" property.
earthImage is loaded in index.js asynchronously using a file stream. Once the file contents are read completely, they are assigned to the image property of $.earthImage.
Notice, the blob you get as a result of "earthBuffer.toBlob()" can't be used for any other image manipulation (e.g. creating thumbnails). It doesn't have a valid height, or width on Android.
E.G.
$.earthImage.image = earthBuffer.toBlob();
Ti.API.info( $.earthImage.image.height + ' . '+ $.earthImage.image.width + ' . '+ $.earthImage.image.mimeType);
Android
04-24 15:11:03.812: I/TiAPI(28395): 0 . 0 . application/octet-stream
iOS
[INFO] 1600 . 2560 . application/octet-stream
[INFO] 1600 . 2560 . application/octet-stream
Issue was reproducible with 3.3.0 and 3.4.0
Attached sample is a native IOS project, do we have a JavaScript titanium sample?
Tried with the following sample and Android works without any issues (I can see 'width' and 'height' and thumbnail creation also works fine.
updated with the right sample code. tested on Nexus 4 running Android 4.0.4 with SDK 3.3.0.GA and master. [~salachi] Do retest with attached sample app.
Tried with the attached sample and I don't see the problem, dimension is returned properly Here is the Log 08-30 21:52:30.093: I/TiAPI(14539): 1600 . 2560 . application/octet-stream 08-30 21:52:30.101: I/TiAPI(14539): 1600 . 2560 . application/octet-stream
Replaced the use of getFileExtensionFromUrl as it is for encoded url and won't work with path with special characters. https://github.com/appcelerator/titanium_mobile/pull/6216
Test case copied from TC var picture1 = 'picture@2x.png'; var file1 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, picture1); var blob1 = file1.read(); Ti.API.info('blob: ' + JSON.stringify(blob1, null, 2)); var picture2 = 'pic@ture.png'; var file2 = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, picture2); var blob2 = file2.read(); Ti.API.info('blob: ' + JSON.stringify(blob2, null, 2));
I tried it with the PR: https://github.com/appcelerator/titanium_mobile/pull/6216 and the MapModule.zip code. The log for height and width was as follows: [INFO] : 0 . 0 . application/octet-stream Adding comments for a possible fix in the pull request.
Verified fix using: Mac OSX 10.10.2 Appcelerator Studio, build: 4.0.0.201502051633 Titanium SDK build: 4.0.0.v20150211081857 Titanium CLI, build: 3.6.0-dev Alloy: 1.5.1 Android Build tools 21.1.1 Nexus 5 (5.0.1), Galaxy S3 (4.4.2) Built to both devices, when converting the blob to an image the dimensions are maintained. Closing ticket.