Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

image-data-uri

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

image-data-uri

Library to easily decode/encode Data URI images

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-19.87%
Maintainers
1
Weekly downloads
 
Created
Source

Image Data URI

Library to easily decode/encode Data URI images

Install

NPM / Node

npm install image-data-uri

Methods

  • decode(dataURI)
imageDataURI.decode('data:image/png;base64,SOMEPNGDATAURI/wD/')

// RETURNS
{
    imageType: 'png',
    dataBase64: 'SOMEPNGDATAURI/wD/',
    dataBuffer: <Buffer 89 50 4e 47 0d 0a ...>
}
  • encode(data, mediaType)
// Expects a Buffer of a image file
let dataBuffer = new Buffer(imageData);

// PNG | GIF | etc.
let mediaType = 'PNG';

// RETURNS :: image data URI :: 'data:image/png;base64,PNGDATAURI/wD/'
imageDataURI.encode(dataBuffer, mediaType)
  • encodeFromURL(imageURL)
// Returns a Promise
imageDataURI.encodeFromURL('http://www.some-site.com/some-image.png')

    // RETURNS image data URI :: 'data:image/png;base64,PNGDATAURI/'
    .then(res => console.log(res))
  • encodeFromFile(filePath)
// Returns a Promise
imageDataURI.encodeFromFile('./some-file.png')

    // RETURNS image data URI :: 'data:image/png;base64,PNGDATAURI/'
    .then(res => console.log(res))
  • outputFile(dataURI, filePath)
// Some image data uri
let dataURI = 'data:image/png;base64,PNGDATAURI/';

// It will create the full path in case it doesn't exist
let filePath = './out/path/fileName';

// Returns a Promise
imageDataURI.outputFile(dataURI, filePath)

    // RETURNS image path of the created file 'out/path/fileName.png'
    .then(res => console.log(res))

Keywords

FAQs

Package last updated on 02 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc