[TIMOB-24141] iOS: TiBlob.imageAsResized resizing the Blob image but file size is very high (JPG)
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-11-14T06:35:19.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.1.0 |
Components | iOS |
Labels | supportTeam |
Reporter | Meenakshi Pathak |
Assignee | Hans Knöchel |
Created | 2013-03-18T11:58:25.000+0000 |
Updated | 2017-01-05T00:37:46.000+0000 |
Description
'imageAsResized' however resizing the Blob image but resulting image size is very high.
var image = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'images.jpeg').read();
Ti.API.info("original image size:" + image.size);
Ti.API.info("original image dimensions: " + image.width + 'x' + image.height);
var newBlob1 = image.imageAsResized(160,120);
Ti.API.info("test 1 image size:" + newBlob1.size);
Ti.API.info("test 1 image dimensions: " + newBlob1.width + 'x' + newBlob1.height);
var bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test.jpeg');
bgImage.write(newBlob1);
Note: This issue is found with JPG images.However it is working fine in .png files.
File extension is jpeg(jpg), but actual contents are png. This problem occurs similarly in imageAsThumbnail() and imageAsCropped(). Mimetype is detected by whether the image has alpha in Tiblob.m(Line 112). UIImageResize set to alpha(kCGImageAlphaPremultipliedLast) in UIImage+Resize.m(Line 49). Therefore, mimetype is set to png.
Here is a workaround that works for me on iOS : use Ti.ImageFactory.compress to force jpeg format
Thank you all. Is anyone able to file a PR based on these findings? If so, we'd be happy to merge it in.
So I looked into this. The method is meant to be used for resizing, not compressing. While PNG's will auto-compress because of the image/png mime-type, jpg-images (image/jpeg) won't. So I would suggest to either add the
compress
method from Ti.ImageFactory inside the core (likeimageAsCompressed
) or use the official Ti.ImageFactory module which is meant for exactly this use-cases. The suggested method would be quite simple:Feedback appreciated *EDIT*: Moved the issue to TIMOB since the issue is not occurring in the module but in the core-method.
PR: https://github.com/appcelerator/titanium_mobile/pull/8602 Test-Case:
Verified fixed, am able to view the compressed image which is set to the dimensions 200X200 on jpegs using the test coded provided by [~hansknoechel] *Environement*