mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-15 04:40:02 +01:00
Added exportBin method
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -36,3 +36,4 @@ node_modules
|
||||
todo.txt
|
||||
test.js
|
||||
output.txt
|
||||
output/
|
||||
|
||||
6
index.js
6
index.js
@@ -1,11 +1,13 @@
|
||||
console.log('\x1b[31m%s\x1b[0m',"This is the output of the module");
|
||||
require('./src/ImageSequencer');
|
||||
sequencer = ImageSequencer();
|
||||
sequencer.loadImages({images:{red:'examples/red.jpg'},callback:function(){
|
||||
sequencer.loadImages({images:{red:'examples/images/red.jpg'},callback:function(){
|
||||
sequencer.addSteps(['do-nothing-pix','ndvi-red','invert']);
|
||||
sequencer.removeSteps(1);
|
||||
sequencer.insertSteps({
|
||||
red: [{index: -1, name: 'do-nothing-pix', o:{}}]
|
||||
});
|
||||
sequencer.run();
|
||||
sequencer.run(function(){
|
||||
sequencer.exportBin();
|
||||
});
|
||||
}});
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"bootstrap": "~3.2.0",
|
||||
"data-uri-to-buffer": "^2.0.0",
|
||||
"fisheyegl": "^0.1.2",
|
||||
"font-awesome": "~4.5.0",
|
||||
"jquery": "~2",
|
||||
|
||||
52
src/ExportBin.js
Normal file
52
src/ExportBin.js
Normal file
@@ -0,0 +1,52 @@
|
||||
var getDirectories = function(rootDir, cb) {
|
||||
fs.readdir(rootDir, function(err, files) {
|
||||
var dirs = [];
|
||||
if(typeof(files)=="undefined") {
|
||||
cb(dirs);
|
||||
return [];
|
||||
}
|
||||
for (var index = 0; index < files.length; ++index) {
|
||||
var file = files[index];
|
||||
if (file[0] !== '.') {
|
||||
var filePath = rootDir + '/' + file;
|
||||
fs.stat(filePath, function(err, stat) {
|
||||
if (stat.isDirectory()) {
|
||||
dirs.push(this.file);
|
||||
}
|
||||
if (files.length === (this.index + 1)) {
|
||||
return cb(dirs);
|
||||
}
|
||||
}.bind({index: index, file: file}));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = function ExportBin(ref) {
|
||||
if(ref.options.inBrowser) return false;
|
||||
fs.access('./output/', function(err){
|
||||
if(err) fs.mkdir('output', function() {});
|
||||
});
|
||||
getDirectories('./output',function(dirs){
|
||||
var num = 1;
|
||||
for(var d in dirs){
|
||||
if(dirs[d].match(/^sequencer(.*)$/)==null) continue;
|
||||
var n = parseInt(dirs[d].match(/^sequencer(.*)$/)[1]);
|
||||
num = (n>=num)?(n+1):num;
|
||||
}
|
||||
fs.mkdir('output/sequencer'+num,function(){
|
||||
var root = 'output/sequencer'+num+'/';
|
||||
for(var image in ref.images) {
|
||||
var steps = ref.images[image].steps;
|
||||
for(var i in steps) {
|
||||
var datauri = steps[i].output.src;
|
||||
var ext = steps[i].output.format;
|
||||
var buffer = require('data-uri-to-buffer')(datauri);
|
||||
fs.writeFile(root+image+"_"+i+"."+ext,buffer,function(){
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -42,7 +42,8 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
formatInput = require('./FormatInput'),
|
||||
images = {},
|
||||
inputlog = [],
|
||||
events = require('./UserInterface')();
|
||||
events = require('./UserInterface')(),
|
||||
fs = require('fs');
|
||||
|
||||
// if in browser, prompt for an image
|
||||
// if (options.imageSelect || options.inBrowser) addStep('image-select');
|
||||
@@ -175,6 +176,10 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
this.events = require('./UserInterface')(UI);
|
||||
}
|
||||
|
||||
var exportBin = function() {
|
||||
return require('./ExportBin')(this);
|
||||
}
|
||||
|
||||
return {
|
||||
//literals and objects
|
||||
name: "ImageSequencer",
|
||||
@@ -193,6 +198,7 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
replaceImage: replaceImage,
|
||||
run: run,
|
||||
setUI: setUI,
|
||||
exportBin: exportBin,
|
||||
|
||||
//other functions
|
||||
log: log,
|
||||
|
||||
Reference in New Issue
Block a user