{ "id": "111305", "key": "TIMOB-24141", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "17608", "name": "Release 6.1.0", "archived": false, "released": true, "releaseDate": "2017-05-26" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2016-11-14T06:35:19.000+0000", "created": "2013-03-18T11:58:25.000+0000", "priority": { "name": "Low", "id": "4" }, "labels": [ "supportTeam" ], "versions": [], "issuelinks": [ { "id": "30158", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "inwardIssue": { "id": "116916", "key": "TIMOB-15247", "fields": { "summary": "iOS: Ti.Blob.imageAsResized always returns a png image", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "High", "id": "2" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2017-01-05T00:37:46.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "'imageAsResized' however resizing the Blob image but resulting image size is very high.\r\n\r\n{code}\r\nvar image = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'images.jpeg').read();\r\n Ti.API.info(\"original image size:\" + image.size);\r\n Ti.API.info(\"original image dimensions: \" + image.width + 'x' + image.height);\r\n var newBlob1 = image.imageAsResized(160,120);\r\n Ti.API.info(\"test 1 image size:\" + newBlob1.size);\r\n Ti.API.info(\"test 1 image dimensions: \" + newBlob1.width + 'x' + newBlob1.height);\r\n \r\n var bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test.jpeg');\r\n\r\n bgImage.write(newBlob1);\r\n{code}\r\n\r\nNote: This issue is found with JPG images.However it is working fine in .png files.\r\n\r\n", "attachment": [], "flagged": false, "summary": "iOS: TiBlob.imageAsResized resizing the Blob image but file size is very high (JPG)", "creator": { "name": "mpathak", "key": "mpathak", "displayName": "Meenakshi Pathak", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "mpathak", "key": "mpathak", "displayName": "Meenakshi Pathak", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Ti SDK 3.0.2GA\r\niOS 6.1", "closedSprints": [ { "id": 752, "state": "closed", "name": "2016 Sprint 23 SDK", "startDate": "2016-11-05T00:39:37.027Z", "endDate": "2016-11-19T01:39:00.000Z", "completeDate": "2016-11-29T06:51:57.887Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "254509", "author": { "name": "sho130", "key": "sho130", "displayName": "Sho Kawakami", "active": true, "timeZone": "Asia/Tokyo" }, "body": "File extension is jpeg(jpg), but actual contents are png.\r\nThis problem occurs similarly in imageAsThumbnail() and imageAsCropped().\r\n\r\nMimetype is detected by whether the image has alpha in Tiblob.m(Line 112).\r\nUIImageResize set to alpha(kCGImageAlphaPremultipliedLast) in UIImage+Resize.m(Line 49).\r\nTherefore, mimetype is set to png. \r\n", "updateAuthor": { "name": "sho130", "key": "sho130", "displayName": "Sho Kawakami", "active": true, "timeZone": "Asia/Tokyo" }, "created": "2013-05-29T06:45:14.000+0000", "updated": "2013-05-29T06:45:14.000+0000" }, { "id": "261621", "author": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "body": "Here is a workaround that works for me on iOS : use Ti.ImageFactory.compress to force jpeg format\r\n\r\n{code:javascript}\r\n// read source image\r\nvar sourceImage = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'source.jpg').read();\r\n\r\n// resize it using core Ti.Blob.imageAsResized()\r\nvar resizedImage = sourceImage.imageAsResized(160,120);\r\n\r\n// do this step if ios only \r\nif (OS_IOS)\r\n{\r\n // choose desired compression level (from 0.0 to 1.0) \r\n var compression_level = 0.75; \r\n\r\n // load ImageFactory module\r\n var ImageFactory = require('ti.imagefactory');\r\n \r\n // convert image to jpeg\r\n resizedImage = ImageFactory.compress( resizedImage, compression_level ); \r\n}\r\n\r\n// create destination file\r\nvar destFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'destination.jpg');\r\n\r\n// write resized image to destination file\r\ndestFile.write(resizedImage);\r\n{code}", "updateAuthor": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-07-12T12:16:27.000+0000", "updated": "2013-07-12T12:16:27.000+0000" }, { "id": "348588", "author": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Thank you all. Is anyone able to file a PR based on these findings? If so, we'd be happy to merge it in.", "updateAuthor": { "name": "ingo", "key": "ingo", "displayName": "Ingo Muschenetz", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2015-04-06T13:36:37.000+0000", "updated": "2015-04-06T13:36:37.000+0000" }, { "id": "400826", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "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 (like {{imageAsCompressed}}) or use the official Ti.ImageFactory module which is meant for exactly this use-cases. The suggested method would be quite simple:\r\n{code:objc}\r\n- (id)imageAsCompressed:(id)args\r\n{\r\n [self ensureImageLoaded];\r\n if (image != nil) {\r\n ENSURE_ARG_COUNT(args,1);\r\n \r\n float compressionQuality = [TiUtils floatValue:[args objectAtIndex:0] def:1.0];\r\n return [[[TiBlob alloc] initWithData:UIImageJPEGRepresentation(image, compressionQuality) mimetype:@\"image/jpeg\"] autorelease];\r\n }\r\n return nil;\r\n}\r\n{code}\r\nFeedback appreciated\r\n\r\n*EDIT*: Moved the issue to TIMOB since the issue is not occurring in the module but in the core-method.", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-11-11T21:09:54.000+0000", "updated": "2016-11-11T21:35:18.000+0000" }, { "id": "400827", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "PR: https://github.com/appcelerator/titanium_mobile/pull/8602\r\n\r\nTest-Case:\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: \"#fff\"\r\n});\r\n\r\nvar btn = Ti.UI.createButton({\r\n title: \"Resize, compress and write\"\r\n});\r\n\r\nbtn.addEventListener(\"click\", function() {\r\n var image = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'test.jpg').read();\r\n Ti.API.info(\" - original image size:\" + image.size);\r\n Ti.API.info(\" - original image dimensions: \" + image.width + 'x' + image.height);\r\n Ti.API.info(\" - original image path: \" + image.nativePath);\r\n \r\n var newBlob1 = image.imageAsResized(200, 200);\r\n Ti.API.info(\" - test 1 image size:\" + newBlob1.size);\r\n Ti.API.info(\" - test 1 image dimensions: \" + newBlob1.width + 'x' + newBlob1.height);\r\n \r\n newBlob1 = newBlob1.imageAsCompressed(0.1); // 10 % of the original quality\r\n \r\n var bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test_200_200.jpg');\r\n Ti.API.info(\" - test 1 image path: \" + bgImage.nativePath);\r\n \r\n bgImage.write(newBlob1);\r\n});\r\n\r\nwin.add(btn);\r\nwin.open();\r\n{code}", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2016-11-11T21:38:34.000+0000", "updated": "2016-11-11T21:38:34.000+0000" }, { "id": "404110", "author": { "name": "smohammed", "key": "smohammed", "displayName": "Samir Mohammed", "active": true, "timeZone": "America/Los_Angeles" }, "body": "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]\r\n*Environement*\r\n{code:java}\r\nAppcelerator Command-Line Interface, version 6.1.0\r\niphone 6 (ios 10.2) simulator\r\niphone 6 plus (ios 9.3.4)\r\nOperating System Name: Mac OS X El Capitan\r\nOperating System Version: 10.11.6\r\nNode.js Version: 4.6.0\r\nnpm: 4.2.8\r\nTitanium SDK Version: 6.1.0.v20170104112531\r\nXcode: 8.2\r\nAppcelerator Studio: 4.8.1.201612050850\r\n{code}\r\n", "updateAuthor": { "name": "smohammed", "key": "smohammed", "displayName": "Samir Mohammed", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2017-01-05T00:37:30.000+0000", "updated": "2017-01-05T00:37:30.000+0000" } ], "maxResults": 8, "total": 8, "startAt": 0 } } }