{ "id": "116916", "key": "TIMOB-15247", "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": [], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2015-04-16T18:21:32.000+0000", "created": "2013-07-05T16:05:43.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "blob", "image", "jpeg", "parity", "png" ], "versions": [], "issuelinks": [ { "id": "30158", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "outwardIssue": { "id": "111305", "key": "TIMOB-24141", "fields": { "summary": "iOS: TiBlob.imageAsResized resizing the Blob image but file size is very high (JPG)", "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": "Low", "id": "4" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2017-03-31T22:22:06.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" } ], "attachment": [], "flagged": false, "summary": "iOS: Ti.Blob.imageAsResized always returns a png image", "creator": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "environment": "Titanium Studio 3.1.1, iOS", "closedSprints": [ { "id": 371, "state": "closed", "name": "2015 Sprint 08 SDK", "startDate": "2015-04-11T00:00:49.626Z", "endDate": "2015-04-24T12:00:00.000Z", "completeDate": "2015-04-28T15:02:06.073Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "261545", "author": { "name": "dsefton", "key": "dsefton", "displayName": "Daniel Sefton", "active": true, "timeZone": "America/Los_Angeles" }, "body": "A simple test case would be nice :)", "updateAuthor": { "name": "dsefton", "key": "dsefton", "displayName": "Daniel Sefton", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-07-12T00:01:11.000+0000", "updated": "2013-07-12T00:01:11.000+0000" }, { "id": "261622", "author": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "updateAuthor": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-07-12T12:20:27.000+0000", "updated": "2013-07-12T12:20:27.000+0000" }, { "id": "261623", "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.\nThis workaround requires the [ImageFactory|https://marketplace.appcelerator.com/apps/4973] module ([github|https://github.com/appcelerator/titanium_modules/tree/master/imagefactory]).\n\n{code:javascript}\n// read source image\nvar sourceImage = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'source.jpg').read();\n\n// resize it using core Ti.Blob.imageAsResized()\nvar resizedImage = sourceImage.imageAsResized(160,120);\n\n// do this step if ios only \nif (OS_IOS)\n{\n // choose desired compression level (from 0.0 to 1.0) \n var compression_level = 0.75; \n\n // load ImageFactory module\n var ImageFactory = require('ti.imagefactory');\n \n // convert image to jpeg\n resizedImage = ImageFactory.compress( resizedImage, compression_level ); \n}\n\n// create destination file\nvar destFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'destination.jpg');\n\n// write resized image to destination file\ndestFile.write(resizedImage);\n{code}", "updateAuthor": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-07-12T12:26:30.000+0000", "updated": "2013-07-12T12:26:30.000+0000" }, { "id": "270409", "author": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "body": "This issue requires a Test Case. ", "updateAuthor": { "name": "mpmiranda", "key": "mpmiranda", "displayName": "Mauro Parra-Miranda", "active": true, "timeZone": "America/Mexico_City" }, "created": "2013-09-09T20:47:33.000+0000", "updated": "2013-09-09T20:47:33.000+0000" }, { "id": "270557", "author": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "body": "Test case:\n\n{code:javascript}\nvar image = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, 'srcImage.jpg').read();\nTi.API.info(\"original image size:\" + image.size);\nTi.API.info(\"original image dimensions: \" + image.width + 'x' + image.height);\nvar newBlob1 = image.imageAsResized(160,120);\nTi.API.info(\"test 1 image size:\" + newBlob1.size);\nTi.API.info(\"test 1 image dimensions: \" + newBlob1.width + 'x' + newBlob1.height);\n\nvar bgImage = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'test.jpg');\n\nbgImage.write(newBlob1);\n//\n// => Even though the output filename contains .jpg, it's a png file that is created (but named 'test.jpg')\n//\n// There's two ways to verify that it's a png file that has been created:\n// 1) the file is large (much larger than if it had been saved as jpeg)\n// 2) viewing the file with an \"advanced\" image viewer (like, for instance, IrfanView on Windows), one can check that the filetype is actually png rather than jpg\n//\n{code}", "updateAuthor": { "name": "lulu", "key": "lulu", "displayName": "Cedric Paternotte", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-09-10T09:08:41.000+0000", "updated": "2013-09-10T09:08:41.000+0000" }, { "id": "300754", "author": { "name": "giorgos29cm", "key": "giorgos29cm", "displayName": "Giorgos Papadopoulos", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hi,\r\n\r\nI solved this issue.\r\n\r\nThe problem lies in the UIImage+Resize.m\r\n\r\nWhen the image is resized in the \r\n\r\n+ (UIImage *)resizedImage:(CGSize)newSize\r\n transform:(CGAffineTransform)transform\r\n drawTransposed:(BOOL)transpose\r\n interpolationQuality:(CGInterpolationQuality)quality \r\n\t\t\t\t\timage:(UIImage*)image \r\n\t\t\t\t\thires:(BOOL)hires\r\n\r\nit is always assumed that the image has an alpha channel by passing kCGImageAlphaPremultipliedLast when the bitmap context is created. The passed image has first to be checked if it has an alpha channel or not and then create the bitmap context accordingly.\r\n\r\nLong story short: replace kCGImageAlphaPremultipliedLast with [UIImageAlpha hasAlpha:image] ? kCGImageAlphaPremultipliedLast : kCGImageAlphaNoneSkipFirst at line 49 of this file.\r\n\r\nTested and works on Ti 3.2.2.GA, iOS 7.1, simualtor iPhone 3.5''", "updateAuthor": { "name": "giorgos29cm", "key": "giorgos29cm", "displayName": "Giorgos Papadopoulos", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2014-04-13T11:39:01.000+0000", "updated": "2014-04-13T11:39:01.000+0000" }, { "id": "316912", "author": { "name": "paul h", "key": "paul h", "displayName": "Paul Hamilton", "active": true, "timeZone": "America/Havana" }, "body": "Android seems to be returning a bitmap. \"image/bitmap\" mimetype. Can anything be done about this?", "updateAuthor": { "name": "paul h", "key": "paul h", "displayName": "Paul Hamilton", "active": true, "timeZone": "America/Havana" }, "created": "2014-08-04T19:59:50.000+0000", "updated": "2014-08-04T19:59:50.000+0000" }, { "id": "348587", "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:25.000+0000", "updated": "2015-04-06T13:36:25.000+0000" }, { "id": "349302", "author": { "name": "underlabs", "key": "underlabs", "displayName": "Joseph Sachs", "active": true, "timeZone": "America/Montreal" }, "body": "I'm going to try out [~giorgos29cm]'s suggestion & will update my results.", "updateAuthor": { "name": "underlabs", "key": "underlabs", "displayName": "Joseph Sachs", "active": true, "timeZone": "America/Montreal" }, "created": "2015-04-13T11:54:26.000+0000", "updated": "2015-04-13T11:54:26.000+0000" }, { "id": "349672", "author": { "name": "underlabs", "key": "underlabs", "displayName": "Joseph Sachs", "active": true, "timeZone": "America/Montreal" }, "body": "For me [~lulu]'s use of *ImageFactory* has been the best option. I did not see a difference on iOS with [~giorgos29cm] modification. Someone can double check.\r\n\r\nResult on *Android* - image.imageAsResized...):\r\n1- image Original size: undefined\r\n image Original dimensions: 3264x2448\r\n2- image size Resize :undefined\r\n image dimensions After Resize: 853x640\r\n3- image JPG image size: 58551 (very decent for a Camera Snapshot on a Samsung S3)\r\n\r\nOn *iOS* (different Image with ImageFactory.compress(image.imageAsResized...), 0.75):\r\n1- image Original size: 1500000 \r\n image Original dimensions: 1500x1000\r\n2- image size Resize: 614400\r\n image dimensions After Resize: 640x960\r\n3- image JPG image size: 233242 ", "updateAuthor": { "name": "underlabs", "key": "underlabs", "displayName": "Joseph Sachs", "active": true, "timeZone": "America/Montreal" }, "created": "2015-04-15T11:31:57.000+0000", "updated": "2015-04-15T11:32:51.000+0000" }, { "id": "349677", "author": { "name": "timpoulsen", "key": "timpoulsen", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/Havana" }, "body": "Cedric's workaround has worked for me. I don't have the stats handy, but pre-workaround, resized images were around 2MB and I confirmed were PNG data in a blob otherwise identified as a JPG. Post-workaround, sizes are around 150KB w/JPG data in the blob. I have not tried Giorgos' modification.", "updateAuthor": { "name": "timpoulsen", "key": "timpoulsen", "displayName": "Tim Poulsen", "active": true, "timeZone": "America/Havana" }, "created": "2015-04-15T13:41:26.000+0000", "updated": "2015-04-15T13:41:26.000+0000" }, { "id": "349751", "author": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Pull pending\r\nmaster - https://github.com/appcelerator/titanium_mobile/pull/6783", "updateAuthor": { "name": "vduggal", "key": "vduggal", "displayName": "Vishal Duggal", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2015-04-15T21:38:43.000+0000", "updated": "2015-04-15T21:38:43.000+0000" }, { "id": "356218", "author": { "name": "michael", "key": "michael", "displayName": "Michael Gangolf", "active": true, "timeZone": "Europe/Berlin" }, "body": "the PR above was merged 16 Apr, but with 4.0.0.GA I still have a png on iOS when just using imageAsResized", "updateAuthor": { "name": "michael", "key": "michael", "displayName": "Michael Gangolf", "active": true, "timeZone": "Europe/Berlin" }, "created": "2015-06-29T12:35:04.000+0000", "updated": "2015-06-29T12:35:04.000+0000" }, { "id": "416589", "author": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Closing ticket as fixed, if there are any problems, please file a new ticket.", "updateAuthor": { "name": "lmorris", "key": "lmorris", "displayName": "Lee Morris", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2017-03-31T22:22:06.000+0000", "updated": "2017-03-31T22:22:06.000+0000" } ], "maxResults": 17, "total": 17, "startAt": 0 } } }