Image Data URI
Library to easily decode/encode Data URI images
Install
NPM / Node
npm install image-data-uri
Methods
imageDataURI.decode('data:image/png;base64,SOMEPNGDATAURI/wD/')
{
imageType: 'png',
dataBase64: 'SOMEPNGDATAURI/wD/',
dataBuffer: <Buffer 89 50 4e 47 0d 0a ...>
}
let dataBuffer = new Buffer(imageData);
let mediaType = 'PNG';
imageDataURI.encode(dataBuffer, mediaType)
imageDataURI.encodeFromURL('http://www.some-site.com/some-image.png')
.then(res => console.log(res))
imageDataURI.encodeFromFile('./some-file.png')
.then(res => console.log(res))
- outputFile(dataURI, filePath)
let dataURI = 'data:image/png;base64,PNGDATAURI/';
let filePath = './out/path/fileName';
imageDataURI.outputFile(dataURI, filePath)
.then(res => console.log(res))