How can I open data: image in browser from node-webkit app?
I am using Node -Webkit to build an image enhancement app. I have a download button that is clicked like this.
document.getElementById("download").onclick = function(){
var c = Caman("canvas");
if(file.type.replace("image/","")=="jpeg"){
//save as jpeg
c.save('jpeg');
} else {
//saves as png by default
c.save();
}
}
}
This function should load the image if it is running in the browser, but the loading does not work in the Node-Webkit app.
So, I want to make it a function to open data: image in the default browser so that I can save the image from the browser, but I have no idea how. Can anyone help me with this?
Thank.
source to share
Node-Webkit supports the node.js filesystem API . This way you can use fs.writeFile to save the file.
Or you can take a look at node-webkit-fdialogs which should make things easier for you.
If you want to use the node library, you just need require
in your javascript as in node. Take a look at an example:
var fs = require("fs");
$('#saveButton').click(function() {
var canvasImage = canvas.toDataURL("image/png").split(',')[1];
var decodedImg = window.atob(canvasImage);
var img = new Buffer(decodedImg, encoding='base64');
fs.writeFile("output.png", img, function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});
});
source to share