cordova-plugin-canvas-to-image

0.8.0 • Public • Published

Canvas2ImagePlugin

This plugin allows you to save the contents of an HTML canvas tag to the iOS Photo Library, Android Gallery or WindowsPhone 8 Photo Album from your app. On Android platforms you can change the format of the saved files (png/jpg) and define the folder where to save the pictures .

Installation

cordova plugin add cordova-plugin-canvas-to-image

Usage:

Call the window.canvas2ImagePlugin.saveImageDataToLibrary() method using success and error callbacks and the id attribute or the element object of the canvas to save:

Example

<canvas id="myCanvas" width="165px" height="145px"></canvas>
function onDeviceReady()
{
    window.canvas2ImagePlugin.saveImageDataToLibrary(
        function(msg){
            console.log(msg);  //msg is the filename path (for android and iOS)
        },
        function(err){
            console.log(err);
        },
        document.getElementById('myCanvas')
    );
}
function onDeviceReady()
{
    window.canvas2ImagePlugin.saveImageDataToLibrary(
        function(msg){
            console.log(msg);  //msg is the filename path (for android and iOS)
        },
        function(err){
            console.log(err);
        },
        document.getElementById('myCanvas'),
        '.jpg',
        80
    );
}
 
```javascript  ... format: jpg   ... quality 80% ... outputfolder : 'canvaspluginfolder'
function onDeviceReady()
{
    window.canvas2ImagePlugin.saveImageDataToLibrary(
        function(msg){
            console.log(msg);  //msg is the filename path (for android and iOS)
        },
        function(err){
            console.log(err);
        },
        document.getElementById('myCanvas'),
        '.jpg',
        80,
        'cunvaspluginfolder'
    );
}
 
with this plugin its easy to create a picture, add some text to the picture and save the edited picture to galery or wehre ever you want ! 

Package Sidebar

Install

npm i cordova-plugin-canvas-to-image

Weekly Downloads

2

Version

0.8.0

License

Apache-2.0

Unpacked Size

18.6 kB

Total Files

9

Last publish

Collaborators

  • liuxy