convert img to base64, or convert base64 to img
Switch branches/tags
Nothing to show
Clone or download
廖伟 廖伟
廖伟 and 廖伟 support svg
Latest commit 28af7ac Feb 13, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
test support svg file Feb 13, 2018
.gitignore support svg file Feb 13, 2018
Gruntfile.js first commit Mar 2, 2015 support svg Feb 13, 2018
base64-img.js support svg file Feb 13, 2018
package.json support svg Feb 13, 2018


Convert img to base64, or convert base64 to img

var base64Img = require('base64-img');


npm install base64-img --save




.base64(filename, callback)

Convert image file to image base64 data

  • {string} filename required
    The image path
  • {function} callback(err, data) required
    Callback with image base64 data
base64Img.base64('path/demo.png', function(err, data) {})


The api same as base64, but it's synchronous

var data = base64Img.base64Sync('path/demo.png');
var data2 = base64Img.base64Sync('path/demo.svg');

.requestBase64(url, callback)

  • {string} url required
  • {function} callback(err, res, body) required
    Callback with http request
var url = 'http://../demo.png';
base64Img.requestBase64(url, function(err, res, body) {

.img(data, destpath, name, callback)

Convert image base64 data to image

  • {string} data required
    Image base64 data
  • {string} destpath required
    Dest path, if the destpath is root, pass empty string
  • {string} name required
    The image's filename
  • {function} callback(err, filepath) required
base64Img.img('data:image/png;base64,...', 'dest', '1', function(err, filepath) {});

.imgSync(data, destpath, name)

The api same as img, but it's synchronous

var filepath = base64Img.imgSync('data:image/png;base64,...', '', '2');