Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Library to easily decode/encode Data URI images

NotificationsYou must be signed in to change notification settings

DiegoZoracKy/image-data-uri

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.decode('data:image/png;base64,SOMEPNGDATAURI/wD/')// RETURNS{imageType:'image/png',dataBase64:'SOMEPNGDATAURI/wD/',dataBuffer:<Buffer89504e470d0a...>}
  • encode(data, mediaType)
// Expects a Buffer of a image fileletdataBuffer=newBuffer(imageData);// PNG | GIF | etc.letmediaType='PNG';// RETURNS :: image data URI :: 'data:image/png;base64,PNGDATAURI/wD/'imageDataURI.encode(dataBuffer,mediaType)
  • encodeFromURL(imageURL)
// Returns a PromiseimageDataURI.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 PromiseimageDataURI.encodeFromFile('./some-file.png')// RETURNS image data URI :: 'data:image/png;base64,PNGDATAURI/'.then(res=>console.log(res))
  • outputFile(dataURI, filePath)
// Some image data uriletdataURI='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 URIletfilePath='./out/path/fileName';// Returns a PromiseimageDataURI.outputFile(dataURI,filePath)// RETURNS image path of the created file 'out/path/fileName.png'.then(res=>console.log(res))

About

Library to easily decode/encode Data URI images

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors5


[8]ページ先頭

©2009-2025 Movatter.jp