Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b26b55a061 | |||
| bac8ff71a3 | |||
| ed8a8f13d3 | |||
| 3d740e8e63 | |||
| 1eb312609c | |||
| ce3f8563c4 | |||
| 59998f3950 | |||
| e4dfa52b05 | |||
| 4080c64451 | |||
| c744de9fb1 | |||
| e2dcccf17e | |||
| d0f536a8b9 | |||
| ec45e6aabb | |||
| c4009429a4 | |||
| a4e55d33c7 | |||
| a6aaccb601 | |||
| 0189a7b7bd | |||
| 4ca9499c95 | |||
| 9182f20d32 |
@@ -1,5 +1,6 @@
|
|||||||
# Commons
|
# Commons
|
||||||
/node_modules
|
/node_modules
|
||||||
|
*.log
|
||||||
|
|
||||||
# OS
|
# OS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Make NPM module leaner
|
||||||
|
|
||||||
|
/scripts
|
||||||
|
.eslintrc
|
||||||
|
.npmrc
|
||||||
@@ -3,6 +3,12 @@ This plugin (based on [devgeeks/Canvas2ImagePlugin](http://github.com/devgeeks/C
|
|||||||
|
|
||||||
The plugin is a kind of fork of the [solderzzc/Base64ImageSaverPlugin](https://github.com/solderzzc/Base64ImageSaverPlugin) but with a cleaner history (a.k.a: no tags from Canvas2ImagePlugin repo).
|
The plugin is a kind of fork of the [solderzzc/Base64ImageSaverPlugin](https://github.com/solderzzc/Base64ImageSaverPlugin) but with a cleaner history (a.k.a: no tags from Canvas2ImagePlugin repo).
|
||||||
|
|
||||||
|
## Alert
|
||||||
|
In order to be more consistent with the cordova naming convention, since version 2.0 the repository name and the cordova plugin id have changed to **cordova-base64-to-gallery** (issue #1).
|
||||||
|
|
||||||
|
Please uninstall the old version and reinstall the new one.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
Call the `cordova.base64ToGallery()` method using success and error callbacks and the id attribute or the element object of the canvas to save:
|
Call the `cordova.base64ToGallery()` method using success and error callbacks and the id attribute or the element object of the canvas to save:
|
||||||
|
|
||||||
|
|||||||
+15
-18
@@ -1,22 +1,20 @@
|
|||||||
{
|
{
|
||||||
"name": "cordova-base64-to-gallery",
|
"name": "cordova-base64-to-gallery",
|
||||||
"version": "1.0.1",
|
"version": "2.0.2",
|
||||||
"description": "Cordova plugin to save base64 data as a png image into the device",
|
"description": "Cordova plugin to save base64 data as a png image into the device",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts":
|
"scripts": {
|
||||||
{
|
"update": "node ./scripts/update_version",
|
||||||
"lint": "eslint www/base64ToGallery.js",
|
"lint": "eslint www/base64ToGallery.js",
|
||||||
"test": "npm run lint",
|
"test": "npm run lint",
|
||||||
"prepublish": "npm test"
|
"prepublish": "npm test"
|
||||||
},
|
},
|
||||||
"repository":
|
"repository": {
|
||||||
{
|
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/Nexxa/base64ToGallery.git"
|
"url": "git+https://github.com/Nexxa/cordova-base64-to-gallery.git"
|
||||||
},
|
},
|
||||||
"bugs":
|
"bugs": {
|
||||||
{
|
"url": "https://github.com/Nexxa/cordova-base64-to-gallery/issues"
|
||||||
"url": "https://github.com/Nexxa/base64ToGallery/issues"
|
|
||||||
},
|
},
|
||||||
"engines": [
|
"engines": [
|
||||||
{
|
{
|
||||||
@@ -26,9 +24,8 @@
|
|||||||
"node": ">=0.10"
|
"node": ">=0.10"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"cordova":
|
"cordova": {
|
||||||
{
|
"id": "cordova-base64-to-gallery",
|
||||||
"id": "it.nexxa.base64ToGallery",
|
|
||||||
"platforms": [
|
"platforms": [
|
||||||
"ios",
|
"ios",
|
||||||
"android",
|
"android",
|
||||||
@@ -40,13 +37,13 @@
|
|||||||
"base64",
|
"base64",
|
||||||
"save",
|
"save",
|
||||||
"photo library",
|
"photo library",
|
||||||
|
"gallery",
|
||||||
"ecosystem:cordova",
|
"ecosystem:cordova",
|
||||||
"cordova-ios",
|
"cordova-ios",
|
||||||
"cordova-android",
|
"cordova-android",
|
||||||
"cordova-wp8"
|
"cordova-wp8"
|
||||||
],
|
],
|
||||||
"author":
|
"author": {
|
||||||
{
|
|
||||||
"name": "StefanoMagrassi",
|
"name": "StefanoMagrassi",
|
||||||
"email": "stefano.magrassi@gmail.com",
|
"email": "stefano.magrassi@gmail.com",
|
||||||
"url": "http://thinkwritedone.com"
|
"url": "http://thinkwritedone.com"
|
||||||
@@ -58,8 +55,8 @@
|
|||||||
"url": "http://www.tiegushi.com"
|
"url": "http://www.tiegushi.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"devDependencies":
|
"devDependencies": {
|
||||||
{
|
"eslint": "1.10.3",
|
||||||
"eslint": "^1.10.3"
|
"nodemsg": "1.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+52
-53
@@ -1,67 +1,66 @@
|
|||||||
<plugin id="it.nexxa.base64ToGallery" version="1.0.1" xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://www.phonegap.com/ns/plugins/1.0">
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<plugin xmlns:android="http://schemas.android.com/apk/res/android" xmlns="http://www.phonegap.com/ns/plugins/1.0" id="cordova-base64-to-gallery" version="2.0.2">
|
||||||
|
|
||||||
|
<engines>
|
||||||
|
<engine name="cordova-ios" version="<3.8.0" />
|
||||||
|
</engines>
|
||||||
|
|
||||||
<name>base64ToGallery</name>
|
<name>base64ToGallery</name>
|
||||||
|
|
||||||
<engines>
|
<description>This plugin allows you to save base64 data as a png image into the device (iOS Photo Library, Android Gallery, WindowsPhone 8 Photo Album).</description>
|
||||||
<engine name="cordova" version=">=3.0.0" />
|
<author>Tommy-Carlos Williams - tommy@devgeeks.org</author>
|
||||||
</engines>
|
<author>Simba Zhang - solderzzc@gmail.com</author>
|
||||||
|
<author>StefanoMagrassi - stefano.magrassi@gmail.com</author>
|
||||||
|
<keywords>base64,png,save,canvas,image,photo library</keywords>
|
||||||
|
|
||||||
<description>This plugin allows you to save base64 data as a png image into the device (iOS Photo Library, Android Gallery, WindowsPhone 8 Photo Album).</description>
|
<license>MIT</license>
|
||||||
<author>Tommy-Carlos Williams - tommy@devgeeks.org</author>
|
|
||||||
<author>Simba Zhang - solderzzc@gmail.com</author>
|
|
||||||
<author>StefanoMagrassi - stefano.magrassi@gmail.com</author>
|
|
||||||
<keywords>base64,png,save,canvas,image,photo library</keywords>
|
|
||||||
|
|
||||||
<license>MIT</license>
|
<js-module name="base64ToGallery" src="www/base64ToGallery.js">
|
||||||
|
<clobbers target="cordova.base64ToGallery"/>
|
||||||
|
</js-module>
|
||||||
|
|
||||||
<js-module name="base64ToGallery" src="www/base64ToGallery.js">
|
<!-- ios -->
|
||||||
<clobbers target="cordova.base64ToGallery"/>
|
<platform name="ios">
|
||||||
</js-module>
|
<source-file compiler-flags="-fno-objc-arc" src="src/ios/Base64ToGallery.m"/>
|
||||||
|
|
||||||
<!-- ios -->
|
<config-file parent="/*" target="config.xml">
|
||||||
<platform name="ios">
|
<feature name="Base64ToGallery">
|
||||||
<config-file parent="/*" target="config.xml">
|
<param name="ios-package" value="Base64ToGallery"/>
|
||||||
<feature name="Base64ToGallery">
|
<param name="onload" value="true"/>
|
||||||
<param name="ios-package" value="Base64ToGallery"/>
|
</feature>
|
||||||
<param name="onload" value="true"/>
|
</config-file>
|
||||||
</feature>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<header-file src="src/ios/Base64ToGallery.h"/>
|
<header-file src="src/ios/Base64ToGallery.h"/>
|
||||||
|
</platform>
|
||||||
|
|
||||||
<source-file compiler-flags="-fno-objc-arc" src="src/ios/Base64ToGallery.m"/>
|
<!-- android -->
|
||||||
</platform>
|
<platform name="android">
|
||||||
|
<source-file src="src/android/Base64ToGallery.java" target-dir="src/it/nexxa/Base64ToGallery"/>
|
||||||
|
|
||||||
<!-- android -->
|
<config-file parent="/*" target="AndroidManifest.xml">
|
||||||
<platform name="android">
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
|
</config-file>
|
||||||
|
|
||||||
<config-file parent="/*" target="AndroidManifest.xml">
|
<config-file parent="/*" target="res/xml/config.xml">
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
<feature name="Base64ToGallery">
|
||||||
</config-file>
|
<param name="android-package" value="it.nexxa.base64ToGallery.Base64ToGallery"/>
|
||||||
|
</feature>
|
||||||
|
</config-file>
|
||||||
|
</platform>
|
||||||
|
|
||||||
<config-file parent="/*" target="res/xml/config.xml">
|
<!-- wp8 -->
|
||||||
<feature name="Base64ToGallery">
|
<platform name="wp8">
|
||||||
<param name="android-package" value="it.nexxa.base64ToGallery.Base64ToGallery"/>
|
<source-file src="src/wp8/Base64ToGallery.cs"/>
|
||||||
</feature>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<source-file src="src/android/Base64ToGallery.java" target-dir="src/it/nexxa/Base64ToGallery"/>
|
<config-file parent="/*" target="config.xml">
|
||||||
|
<feature name="Base64ToGallery">
|
||||||
|
<param name="wp-package" value="Base64ToGallery"/>
|
||||||
|
<param name="onload" value="true"/>
|
||||||
|
</feature>
|
||||||
|
</config-file>
|
||||||
|
|
||||||
</platform>
|
<config-file parent="/Deployment/App/Capabilities" target="Properties/WMAppManifest.xml">
|
||||||
|
<Capability Name="ID_CAP_MEDIALIB_PHOTO"/>
|
||||||
<!-- wp8 -->
|
</config-file>
|
||||||
<platform name="wp8">
|
</platform>
|
||||||
<config-file parent="/*" target="config.xml">
|
</plugin>
|
||||||
<feature name="Base64ToGallery">
|
|
||||||
<param name="wp-package" value="Base64ToGallery"/>
|
|
||||||
<param name="onload" value="true"/>
|
|
||||||
</feature>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<config-file parent="/Deployment/App/Capabilities" target="Properties/WMAppManifest.xml">
|
|
||||||
<Capability Name="ID_CAP_MEDIALIB_PHOTO"/>
|
|
||||||
</config-file>
|
|
||||||
|
|
||||||
<source-file src="src/wp8/Base64ToGallery.cs"/>
|
|
||||||
</platform>
|
|
||||||
</plugin>
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*eslint-env node*/
|
||||||
|
|
||||||
|
// Modules
|
||||||
|
var fs = require('fs');
|
||||||
|
var logger = require('nodemsg');
|
||||||
|
var pkg = require('../package.json');
|
||||||
|
|
||||||
|
// CONSTS
|
||||||
|
var CONFIG_FILE = 'plugin.xml';
|
||||||
|
var PLUGIN_ID = 'cordova-base64-to-gallery';
|
||||||
|
var ERROR_MSG = 'No "version" attribute found - Please check '+ CONFIG_FILE +' ("version" tag must follow "id" tag)';
|
||||||
|
var REGEXP = '(id="' + PLUGIN_ID + '" )(version="\\d+[.]\\d+[.]\\d+")';
|
||||||
|
|
||||||
|
// Logic
|
||||||
|
var version = pkg.version;
|
||||||
|
var regex = new RegExp(REGEXP);
|
||||||
|
var config = fs.readFileSync(CONFIG_FILE, { encoding: 'utf8'});
|
||||||
|
|
||||||
|
// Exit if version tag not found
|
||||||
|
if (!regex.test(config)) {
|
||||||
|
logger.error(ERROR_MSG);
|
||||||
|
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set version
|
||||||
|
config = config.replace(regex, '$1version="' + version + '"');
|
||||||
|
|
||||||
|
fs.writeFileSync(CONFIG_FILE, config);
|
||||||
@@ -53,9 +53,7 @@ public class Base64ToGallery extends CordovaPlugin {
|
|||||||
filePrefix = DEFAULT_FILE_PREFIX;
|
filePrefix = DEFAULT_FILE_PREFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the bitmap from the base64 string
|
// Create the bitmap from the base64 string
|
||||||
Log.d("Base64ToGallery", base64);
|
|
||||||
|
|
||||||
byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
|
byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
|
||||||
Bitmap bmp = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
|
Bitmap bmp = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
|
||||||
|
|
||||||
@@ -99,9 +97,6 @@ public class Base64ToGallery extends CordovaPlugin {
|
|||||||
+ c.get(Calendar.MINUTE)
|
+ c.get(Calendar.MINUTE)
|
||||||
+ c.get(Calendar.SECOND);
|
+ c.get(Calendar.SECOND);
|
||||||
|
|
||||||
|
|
||||||
Log.i("Base64ToGallery", "Android version " + deviceVersion);
|
|
||||||
|
|
||||||
int check = deviceVersion.compareTo("2.3.3");
|
int check = deviceVersion.compareTo("2.3.3");
|
||||||
|
|
||||||
File folder;
|
File folder;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
// MIT Licensed
|
// MIT Licensed
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#import <Cordova/CDVPlugin.h>
|
#import <Cordova/CDVPlugin.h>
|
||||||
|
|
||||||
@interface Base64ToGallery : CDVPlugin
|
@interface Base64ToGallery : CDVPlugin
|
||||||
|
|||||||
+15
-14
@@ -25,26 +25,28 @@
|
|||||||
NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]];
|
NSData* imageData = [NSData dataFromBase64String:[command.arguments objectAtIndex:0]];
|
||||||
|
|
||||||
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
|
UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease];
|
||||||
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
|
|
||||||
|
|
||||||
|
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
|
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
|
||||||
{
|
{
|
||||||
|
CDVPluginResult* result = nil;
|
||||||
|
|
||||||
// Was there an error?
|
// Was there an error?
|
||||||
if (error != NULL)
|
if (error != NULL) {
|
||||||
{
|
NSLog(@"ERROR: %@", error);
|
||||||
// Show error message...
|
|
||||||
NSLog(@"ERROR: %@",error);
|
result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description];
|
||||||
CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_ERROR messageAsString:error.description];
|
|
||||||
[self.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString: self.callbackId]];
|
[self.webView stringByEvaluatingJavaScriptFromString:[result toErrorCallbackString: self.callbackId]];
|
||||||
}
|
|
||||||
else // No errors
|
// No errors
|
||||||
{
|
} else {
|
||||||
// Show message image successfully saved
|
|
||||||
NSLog(@"IMAGE SAVED!");
|
result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK];
|
||||||
CDVPluginResult* result = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsString:@"Image saved"];
|
|
||||||
[self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]];
|
[self.webView stringByEvaluatingJavaScriptFromString:[result toSuccessCallbackString: self.callbackId]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,5 +56,4 @@
|
|||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class Base64ToGallery : BaseCommand
|
|||||||
|
|
||||||
if (picture.Name.Contains(fileName))
|
if (picture.Name.Contains(fileName))
|
||||||
{
|
{
|
||||||
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, "Image saved: " + picture.Name));
|
DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user