Image Data URI
Library to easily decode/encode Data URI images
Installation
npm install image-data-uri
CLI
npm install image-data-uri -g
npx image-data-uri --help
Methods
- decode(dataURI)
imageDataURI // RETURNS imageType: 'image/png' dataBase64: 'SOMEPNGDATAURI/wD/' dataBuffer: <Buffer 89 50 4e 47 0d 0a ...>
- encode(data, mediaType)
// Expects a Buffer of a image filelet dataBuffer = imageData; // PNG | GIF | etc.let mediaType = 'PNG'; // RETURNS :: image data URI :: 'data:image/png;base64,PNGDATAURI/wD/'imageDataURI
- encodeFromURL(imageURL)
// Returns a PromiseimageDataURI // RETURNS image data URI :: 'data:image/png;base64,PNGDATAURI/'
- encodeFromFile(filePath)
// Returns a PromiseimageDataURI // RETURNS image data URI :: 'data:image/png;base64,PNGDATAURI/'
- outputFile(dataURI, filePath)
// Some image data urilet dataURI = 'data:image/png;base64,PNGDATAURI/'; // It will create the full path in case it doesn't exist// If the extension is defined (e.g. fileName.png), it will be preserved, otherwise the lib will try to guess from the Data URIlet filePath = './out/path/fileName'; // Returns a PromiseimageDataURI // RETURNS image path of the created file 'out/path/fileName.png'