DGM.-
DGM.-

Reputation: 151

Canvas to PhotoLibrary [Phonegap]

Well, I have dealed quite well with several images onto canvas and now the questions lays in exporting to Photo library on iOS throught Phonegap. I've read a lot relates to the Phonegap API, and lot of tests as well, but no results.

Is there any plugin for Phongap which allows to access the photo library in IOS? I saw one for Android :(.

If not (I found canvas2image.js) which are your experiences about this topic?

Every info will be apreciated.

Thanks in avance, DGM.-

Upvotes: 1

Views: 3957

Answers (3)

ggDeGreat
ggDeGreat

Reputation: 1196

After few years, the plugin can do more and support IOS previous issued.

Now u can choose either to save as jpg/png, set quality and set outputfolder

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', // save as jpg
        80, // image quality
        'cunvaspluginfolder' //folder name
    );
}

Credit to wbt11a because make this plugin more configurable from original author.

Please download the new plugin here Github source

Upvotes: 1

Devgeeks
Devgeeks

Reputation: 5647

I read this and thought "how hard could it be?".

So I hacked one up real quick.

Let me know if it works OK.

https://github.com/devgeeks/Canvas2ImagePlugin

Example

In your html:

<canvas id="myCanvas" width="165px" height="145px"></canvas>

then in onDeviceReady:

function onDeviceReady()
{
    var canvas2ImagePlugin = window.plugins.canvas2ImagePlugin;
}

then in the function to save your canvas:

// where myCanvasId == 'myCanvas' (the id of the canvas above)
function mySavingFunction(myCanvasId) {
    canvas2ImagePlugin.saveImageDataToLibrary(
        function(msg){
            console.log(msg);
        }, 
        function(err){
            console.log(err);
        }, 
        myCanvasId
    );
}

Upvotes: 5

DGM.-
DGM.-

Reputation: 151

Well, the solutions consists in re-write the khamer's plugin SaveImage from: https://github.com/khamer/phonegap-plugins-official/tree/master/iPhone/SaveImage

Greetings, DGM.-

Upvotes: 0

Related Questions