• Download Gist
create_images_json_object_from_dir.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
var sys = require("sys"),
fs = require("fs");
 
function processImageDir(path, outFilename, cb) {
fs.readdir(path, function(err, files) {
fs.writeFile(__dirname + '/' + outFilename, JSON.stringify({
images: files.filter(function(name) { return /(?:png|jpe?g|gif)$/i.test(name); })
}), function(err) {
if (err) throw err;
cb && cb("Sweet.");
});
 
});
}
 
processImageDir('/path/to/your/images/dir', "preload-images.json", function(message) {
console.log(message);
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.