Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas2ImagePlugin.js:10Uncaught ReferenceError: module is not defined #65

Open
sornanun opened this issue Mar 18, 2016 · 2 comments
Open

Comments

@sornanun
Copy link

I work on ionic framework. I added canvas2ImagePlugin to my project and link it in index.html.
But I have some problem that I don't know how to fix. I'm a beginner with ionic and angularJS.

Error : Canvas2ImagePlugin.js:10Uncaught ReferenceError: module is not defined

module.exports = {   /// I got error this line.
    saveImageDataToLibrary:function(successCallback, failureCallback, canvasId) {
        // successCallback required
        if (typeof successCallback != "function") {
            console.log("Canvas2ImagePlugin Error: successCallback is not a function");
        }
        else if (typeof failureCallback != "function") {
            console.log("Canvas2ImagePlugin Error: failureCallback is not a function");
        }
        else {
            var canvas = (typeof canvasId === "string") ? document.getElementById(canvasId) : canvasId;
            var imageData = canvas.toDataURL().replace(/data:image\/png;base64,/,'');
            return cordova.exec(successCallback, failureCallback, "Canvas2ImagePlugin","saveImageDataToLibrary",[imageData]);
        }
    }
  };

and I will use this code in my controller.js to save image to mobile storage.

var canvas = document.createElement( 'pwCanvasMain' );
        var ctx = canvas.getContext( '2d' );
        void ctx.drawImage( this, 0, 0, img.width, img.height);
        var dataURI = canvas.toDataURL().replace( /data:image\/png;base64,/, '' );
        function successCallback( result ) {
            q.resolve( 'file:///' + result );
        }
        function failureCallback( err ) {
            console.error( err );
            q.reject( err );
        }
        cordova.exec( successCallback, failureCallback, "Canvas2ImagePlugin", "saveImageDataToLibrary", [dataURI] );

I want to convert my canvas as image then save on my mobile device storage. But my issue is module is not defined. Please help. Thanks.

@ghost
Copy link

ghost commented May 19, 2016

@sornanun The correct way to call this plugin inside your controller:

window.canvas2ImagePlugin.saveImageDataToLibrary(
function(msg){
console.log(msg); //This is your successCallback, msg - here should return the local path where the image was stored
},
function(err){
console.log(err); //This is your failureCallback
},
document.getElementById('myCanvas') // This is your canvas id
);

Don't use > cordova.exec( successCallback, failureCallback, "Canvas2ImagePlugin", "saveImageDataToLibrary", [dataURI] ); This is already defined in the plugin interface file.

@commonpike
Copy link

@ghost, that is not the error OP was having ? Also, cordova.exec(..) using a dataURI as last argument is a working (though in this case apparently redundant) call on Android using 0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants