Canvas2ImagePlugin.js fork
//
// Canvas2ImagePlugin.js
// Canvas2ImagePlugin PhoneGap/Cordova plugin
//
// Created by Tommy-Carlos Williams on 29/03/12.
// Copyright (c) 2012 Tommy-Carlos Williams. All rights reserved.
// MIT Licensed
//
(function(root, factory) {
if(typeof define === 'function' && define.amd)
define(factory);
else {
if(!root.plugins) root.plugins = {};
root.canvas2ImagePlugin = factory();
}
}(this, function() {
function canvas2Image(canvas, cb) {
data2Image(canvas.toDataURL(), cb);
}
function data2Image(data, cb) {
if(typeof cb != "function") {
console.log("Data2ImagePlugin Error: cb is not a function");
return;
}
var imageData = data.replace(/data:image\/png;base64,/,'');
if(typeof Cordova !== "undefined") {
cordova.exec(
function(msg) {cb(null, msg);},
function(err) {cb(err);},
"Canvas2ImagePlugin",
"saveImageDataToLibrary",
[imageData]
);
}
}
return {
data2Image: data2Image,
canvas2Image: canvas2Image
}
}));