Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created September 24, 2014 21:33
Show Gist options
  • Save miguelmota/4e9864f182c053d7a51d to your computer and use it in GitHub Desktop.
Save miguelmota/4e9864f182c053d7a51d to your computer and use it in GitHub Desktop.
Base64 to PNG in Node.js
var fs = require('fs');
var path = require('path');
function base64ToPNG(data) {
data = data.replace(/^data:image\/png;base64,/, '');
fs.writeFile(path.resolve(__dirname, '../tmp/image.png'), data, 'base64', function(err) {
if (err) throw err;
});
}
module.exports = base64ToPNG;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment