From 399953cc3bfbe691d1966c02d14ff9259ae823bd Mon Sep 17 00:00:00 2001 From: wbt11a Date: Thu, 7 Aug 2014 11:08:58 -0400 Subject: [PATCH 01/14] Update Canvas2ImagePlugin.m This modification saves the image into the sandboxed directory and returns the absolute path of the image. --- src/ios/Canvas2ImagePlugin.m | 40 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/ios/Canvas2ImagePlugin.m b/src/ios/Canvas2ImagePlugin.m index 734ee00..c9f1cc1 100644 --- a/src/ios/Canvas2ImagePlugin.m +++ b/src/ios/Canvas2ImagePlugin.m @@ -6,27 +6,47 @@ // Copyright (c) 2012 Tommy-Carlos Williams. All rights reserved. // MIT Licensed // +// 99% of this code developed by tommy-carlos williams and ThalesValentim #import "Canvas2ImagePlugin.h" #import +#include @implementation Canvas2ImagePlugin @synthesize callbackId; -//-(CDVPlugin*) initWithWebView:(UIWebView*)theWebView -//{ -// self = (Canvas2ImagePlugin*)[super initWithWebView:theWebView]; -// return self; -//} + +-(void) saveImage:(UIImage *)image withFileName:(NSString *)imageName ofType:(NSString *)extension inDirectory:(NSString *)directoryPath { + if ([[extension lowercaseString] isEqualToString:@"png"]) { + [UIImagePNGRepresentation(image) writeToFile:[directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", imageName, @"png"]] options:NSAtomicWrite error:nil]; + } else if ([[extension lowercaseString] isEqualToString:@"jpg"] || [[extension lowercaseString] isEqualToString:@"jpeg"]) { + [UIImageJPEGRepresentation(image, 1.0) writeToFile:[directoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", imageName, @"jpg"]] options:NSAtomicWrite error:nil]; + } else { + ALog(@"Image Save Failed\nExtension: (%@) is not recognized, use (PNG/JPG)", extension); + } +} + - (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command { + int myRand = arc4random() % 10000000; self.callbackId = command.callbackId; - NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]]; - - UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease]; - UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); - + NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]]; + + UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease]; + + NSString * path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; + NSString *temp = @"ImageFile-"; + NSString *ImageName = [temp stringByAppendingFormat:@"%d",myRand]; + [self saveImage:image withFileName:ImageName ofType:@"png" inDirectory:path]; + NSString *tileDirectory = [[NSBundle mainBundle] resourcePath]; + NSString *documentFolderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; + NSLog(@"Tile Directory: %@", tileDirectory); + NSLog(@"Doc Directory: %@", documentFolderPath); + UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); + CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:[NSString stringWithFormat:@"%@/%@.png", documentFolderPath, ImageName]]; + [self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]]; + } - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo From 821fbb0f05406deeb3e7f555c56fb942a037c7eb Mon Sep 17 00:00:00 2001 From: wbt11a Date: Thu, 7 Aug 2014 11:10:56 -0400 Subject: [PATCH 02/14] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 022f8ab..a73ccbb 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Installation ### NOTE: For older versions of Cordova (You will probably have to use tag 0.2.0) +### Fork Note: This uses some slight modifications of my own combined with the work of ThalesValentim and Tommy-Carlos Williams to return the absolute path of the image in IOS. Usage remains the same. + Usage: ------ From 4e60e4222513a4500f9ed3d4b79a66bba9f536a5 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Thu, 7 Aug 2014 11:13:24 -0400 Subject: [PATCH 03/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a73ccbb..c839011 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Installation ### NOTE: For older versions of Cordova (You will probably have to use tag 0.2.0) -### Fork Note: This uses some slight modifications of my own combined with the work of ThalesValentim and Tommy-Carlos Williams to return the absolute path of the image in IOS. Usage remains the same. +### Fork Note: This uses some minor modifications of my own combined with the work of ThalesValentim and Tommy-Carlos Williams to return the absolute path of the image in IOS, with a semi-unique filename. Usage remains the same. Usage: ------ From d2fe6606679ffdfe1800856f538253ecbf98eb06 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Thu, 7 Aug 2014 11:14:19 -0400 Subject: [PATCH 04/14] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c839011..4eb6d67 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +### Fork Note: This uses some minor modifications of my own combined with the work of ThalesValentim and Tommy-Carlos Williams to return the absolute path of the image in IOS, with a semi-unique filename. Usage remains the same. Essentially, it has been brought inline with the android version. + Canvas2ImagePlugin ============ @@ -15,7 +17,6 @@ Installation ### NOTE: For older versions of Cordova (You will probably have to use tag 0.2.0) -### Fork Note: This uses some minor modifications of my own combined with the work of ThalesValentim and Tommy-Carlos Williams to return the absolute path of the image in IOS, with a semi-unique filename. Usage remains the same. Usage: ------ From cf896752e6b071f1375de2f73274ec742ea2f50d Mon Sep 17 00:00:00 2001 From: wbt11a Date: Thu, 7 Aug 2014 11:28:56 -0400 Subject: [PATCH 05/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4eb6d67..037023a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -### Fork Note: This uses some minor modifications of my own combined with the work of ThalesValentim and Tommy-Carlos Williams to return the absolute path of the image in IOS, with a semi-unique filename. Usage remains the same. Essentially, it has been brought inline with the android version. +### Fork Note: This uses some minor modifications of my own combined with the work of Tommy-Carlos Williams and ThalesValentim to return the absolute path of the image in IOS, with a semi-unique filename. Usage remains the same. Essentially, it has been brought inline with the android version. Canvas2ImagePlugin ============ From fd355e2fe54af586f06518eda95a90d49a12efe1 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Thu, 7 Aug 2014 15:02:21 -0400 Subject: [PATCH 06/14] Update plugin.xml --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index a05a8fa..ce587ed 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="0.7.0"> Canvas 2 Image From 7ba20449628ab24a37248a245f26da9c482f7781 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Thu, 7 Aug 2014 15:03:46 -0400 Subject: [PATCH 07/14] Update plugin.xml --- plugin.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.xml b/plugin.xml index ce587ed..19e6bc8 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,6 +1,6 @@ Canvas 2 Image @@ -9,7 +9,7 @@ - This plugin allows you to save the contents of an HTML canvas tag to the iOS Photo Library, or Android Gallery from your app. + This plugin allows you to save the contents of an HTML canvas tag to the iOS Photo Library, or Android Gallery from your app. It is modified to provide the absolute path to the sandboxed copy in iOS as opposed to adding it to the photo album. Tommy-Carlos Williams - tommy@devgeeks.org canvas,image,photo library From ec8cc877375b63758a36e9b73097257ebd1a993a Mon Sep 17 00:00:00 2001 From: wbt11a Date: Fri, 8 Aug 2014 08:43:29 -0400 Subject: [PATCH 08/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 037023a..450e0c0 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ Installation ### For Cordova 3.0.x: -1. To add this plugin just type: `cordova plugin add https://github.com/devgeeks/Canvas2ImagePlugin.git` or `phonegap local plugin add https://github.com/devgeeks/Canvas2ImagePlugin.git` -2. To remove this plugin type: `cordova plugin remove org.devgeeks.Canvas2ImagePlugin` or `phonegap local plugin remove org.devgeeks.Canvas2ImagePlugin` +1. To add this plugin just type: `cordova plugin add https://github.com/wbt11a/Canvas2ImagePlugin.git` or `phonegap local plugin add https://github.com/wbt11a/Canvas2ImagePlugin.git` +2. To remove this plugin type: `cordova plugin remove org.wbt11a.Canvas2ImagePlugin` or `phonegap local plugin remove org.wbt11a.Canvas2ImagePlugin` ### NOTE: For older versions of Cordova (You will probably have to use tag 0.2.0) From 9462bf834eab29f4d11327f3510a4f25281e4420 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Fri, 8 Aug 2014 09:10:02 -0400 Subject: [PATCH 09/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 450e0c0..4a5fa7a 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ function onDeviceReady() { window.canvas2ImagePlugin.saveImageDataToLibrary( function(msg){ - console.log(msg); + console.log(msg); //msg is the filename path (for android and iOS) }, function(err){ console.log(err); From 90519e01b4bfe638f58c6ccbde282e81fb216d72 Mon Sep 17 00:00:00 2001 From: Keymark Date: Wed, 22 Oct 2014 10:01:51 -0400 Subject: [PATCH 10/14] Changed random filenames to yyyyMMddHHmmss dates --- src/ios/Canvas2ImagePlugin.m | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ios/Canvas2ImagePlugin.m b/src/ios/Canvas2ImagePlugin.m index c9f1cc1..7eab5a9 100644 --- a/src/ios/Canvas2ImagePlugin.m +++ b/src/ios/Canvas2ImagePlugin.m @@ -4,13 +4,14 @@ // // Created by Tommy-Carlos Williams on 29/03/12. // Copyright (c) 2012 Tommy-Carlos Williams. All rights reserved. -// MIT Licensed +// MIT Licensed // // 99% of this code developed by tommy-carlos williams and ThalesValentim #import "Canvas2ImagePlugin.h" #import -#include +#import + @implementation Canvas2ImagePlugin @synthesize callbackId; @@ -29,7 +30,11 @@ -(void) saveImage:(UIImage *)image withFileName:(NSString *)imageName ofType:(NS - (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command { - int myRand = arc4random() % 10000000; + NSDate *date = [NSDate date]; + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; + [dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; + NSString *dateString = [dateFormatter stringFromDate:date]; + self.callbackId = command.callbackId; NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]]; @@ -37,7 +42,7 @@ - (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command NSString * path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *temp = @"ImageFile-"; - NSString *ImageName = [temp stringByAppendingFormat:@"%d",myRand]; + NSString *ImageName = [temp stringByAppendingFormat:@"%d",dateString]; [self saveImage:image withFileName:ImageName ofType:@"png" inDirectory:path]; NSString *tileDirectory = [[NSBundle mainBundle] resourcePath]; NSString *documentFolderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; @@ -56,21 +61,21 @@ - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error context { // Show error message... NSLog(@"ERROR: %@",error); - CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description]; - [self.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString: self.callbackId]]; + CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description]; + [self.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString: self.callbackId]]; } else // No errors { // Show message image successfully saved NSLog(@"IMAGE SAVED!"); - CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:@"Image saved"]; - [self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]]; + CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:@"Image saved"]; + [self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]]; } } - (void)dealloc -{ - [callbackId release]; +{ + [callbackId release]; [super dealloc]; } From e7fbb2a2bacae654c2d0a32fb54207289e835490 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Wed, 22 Oct 2014 10:03:03 -0400 Subject: [PATCH 11/14] Update plugin.xml --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index 19e6bc8..6fc2efb 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + version="0.7.1"> Canvas 2 Image From 7b5532ae264603c46dad8080a17b73a8b9fbaa07 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Fri, 24 Oct 2014 15:39:34 -0400 Subject: [PATCH 12/14] Preparing for merge. --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4a5fa7a..022f8ab 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -### Fork Note: This uses some minor modifications of my own combined with the work of Tommy-Carlos Williams and ThalesValentim to return the absolute path of the image in IOS, with a semi-unique filename. Usage remains the same. Essentially, it has been brought inline with the android version. - Canvas2ImagePlugin ============ @@ -12,12 +10,11 @@ Installation ### For Cordova 3.0.x: -1. To add this plugin just type: `cordova plugin add https://github.com/wbt11a/Canvas2ImagePlugin.git` or `phonegap local plugin add https://github.com/wbt11a/Canvas2ImagePlugin.git` -2. To remove this plugin type: `cordova plugin remove org.wbt11a.Canvas2ImagePlugin` or `phonegap local plugin remove org.wbt11a.Canvas2ImagePlugin` +1. To add this plugin just type: `cordova plugin add https://github.com/devgeeks/Canvas2ImagePlugin.git` or `phonegap local plugin add https://github.com/devgeeks/Canvas2ImagePlugin.git` +2. To remove this plugin type: `cordova plugin remove org.devgeeks.Canvas2ImagePlugin` or `phonegap local plugin remove org.devgeeks.Canvas2ImagePlugin` ### NOTE: For older versions of Cordova (You will probably have to use tag 0.2.0) - Usage: ------ @@ -33,7 +30,7 @@ function onDeviceReady() { window.canvas2ImagePlugin.saveImageDataToLibrary( function(msg){ - console.log(msg); //msg is the filename path (for android and iOS) + console.log(msg); }, function(err){ console.log(err); From 41e2e28a3d85e6c9345b8712081f095291888819 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Fri, 24 Oct 2014 15:40:22 -0400 Subject: [PATCH 13/14] Preparing for merge. --- plugin.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin.xml b/plugin.xml index 6fc2efb..eef118a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,7 +1,7 @@ + id="org.devgeeks.Canvas2ImagePlugin" + version="0.6.1"> Canvas 2 Image @@ -9,7 +9,7 @@ - This plugin allows you to save the contents of an HTML canvas tag to the iOS Photo Library, or Android Gallery from your app. It is modified to provide the absolute path to the sandboxed copy in iOS as opposed to adding it to the photo album. + This plugin allows you to save the contents of an HTML canvas tag to the iOS Photo Library, or Android Gallery from your app. Tommy-Carlos Williams - tommy@devgeeks.org canvas,image,photo library From b4902abe6287d73bde49955bebf4a33db9076f04 Mon Sep 17 00:00:00 2001 From: wbt11a Date: Fri, 24 Oct 2014 15:48:13 -0400 Subject: [PATCH 14/14] ddMMyyyyHHmmss --- src/ios/Canvas2ImagePlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/Canvas2ImagePlugin.m b/src/ios/Canvas2ImagePlugin.m index 7eab5a9..15025bc 100644 --- a/src/ios/Canvas2ImagePlugin.m +++ b/src/ios/Canvas2ImagePlugin.m @@ -32,7 +32,7 @@ - (void)saveImageDataToLibrary:(CDVInvokedUrlCommand*)command { NSDate *date = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init]; - [dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; + [dateFormatter setDateFormat:@"ddMMyyyyHHmmss"]; NSString *dateString = [dateFormatter stringFromDate:date]; self.callbackId = command.callbackId;