Created
July 1, 2014 14:32
-
-
Save jonsherrard/0957d2e3e962bbe18647 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var fs = require("fs"), | |
util = require("util"); | |
var mime = require("mime"); | |
function base64Image(src) { | |
var data = fs.readFileSync(src).toString("base64"); | |
return util.format("data:%s;base64,%s", mime.lookup(src), data); | |
} | |
var srcString, htmlString; | |
fs.readdir('./', function(err, files) { | |
files.filter(function(file) { | |
return (file.substr(-4) == '.png'); | |
}) | |
.forEach(function(file) { | |
srcString = base64Image('./' + file); | |
htmlString = "<img src='" + srcString + "'/>\n"; | |
fs.appendFileSync('./index.html', htmlString, {encoding:"utf-8"}, function() { | |
}); | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment