Skip to content

Instantly share code, notes, and snippets.

@cesarferreira
Forked from miguelmota/base64-to-png.js
Created July 20, 2018 23:42
Show Gist options
  • Select an option

  • Save cesarferreira/c9e05cfd0e66b6d1c79ef88208b773b9 to your computer and use it in GitHub Desktop.

Select an option

Save cesarferreira/c9e05cfd0e66b6d1c79ef88208b773b9 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