Skip to content

Instantly share code, notes, and snippets.

@bebraw
Created July 4, 2012 10:09
Show Gist options
  • Save bebraw/3046527 to your computer and use it in GitHub Desktop.
Save bebraw/3046527 to your computer and use it in GitHub Desktop.
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
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment