You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.2 KiB
74 lines
2.2 KiB
var BOB_mod_gm = require('gm').subClass({ imageMagick: true });
|
|
var BOB_mod_gphoto2 = require('gphoto2');
|
|
var BOB_var_gphoto = new BOB_mod_gphoto2.GPhoto2();
|
|
var BOB_mod_fs = require('fs');
|
|
var BOB_mod_path = require('path');
|
|
var BOB_mod_mkdirp = require('mkdirp');
|
|
|
|
var BOB_cfg_config = null;
|
|
|
|
var BOB_var_camera = null;
|
|
|
|
var BOB_module = {};
|
|
|
|
BOB_upCameraReference(function() {});
|
|
|
|
function BOB_upCameraReference(pCallback) {
|
|
// List cameras / assign list item to variable to use below options
|
|
if( BOB_var_camera === null ) {
|
|
BOB_var_gphoto.list(function (list) {
|
|
if (list.length === 0) {
|
|
return pCallback();
|
|
} else {
|
|
BOB_var_camera = list[0];
|
|
console.log(BOB_var_camera.model);
|
|
return pCallback();
|
|
}
|
|
})
|
|
} else {
|
|
return pCallback();
|
|
}
|
|
}
|
|
|
|
BOB_module.getConfig = function(pCallback) {
|
|
BOB_var_camera.getConfig(pCallback);
|
|
}
|
|
|
|
BOB_module.takePicture = function(pBoothId, pPictId, pCallback) {
|
|
var destPath = BOB_mod_path.join(BOB_cfg_config.paths.original, pBoothId);
|
|
var pictPath = BOB_mod_path.join(destPath, BOB_cfg_config.pictNames[pPictId]);
|
|
|
|
BOB_upCameraReference(function() {
|
|
if( BOB_var_camera === null ) {
|
|
return pCallback("No camera found");
|
|
} else {
|
|
BOB_var_camera.takePicture({download: true}, function (pErr, pData) {
|
|
// If error occurs
|
|
if( pErr ) {
|
|
return pCallback(pErr)
|
|
// Else write file on ddisk
|
|
} else {
|
|
BOB_mod_mkdirp(destPath, function() {
|
|
BOB_mod_fs.writeFile(pictPath, pData, function(pErr) {
|
|
BOB_mod_gm(pictPath)
|
|
.autoOrient()
|
|
.gravity('Center')
|
|
.resize(BOB_cfg_config.cropSize.width, BOB_cfg_config.cropSize.height, "^")
|
|
.crop(BOB_cfg_config.cropSize.width, BOB_cfg_config.cropSize.height)
|
|
// .modulate(100, 0)
|
|
// .contrast(+2)
|
|
.write(dstPict, function(pErr) {
|
|
return pCallback(pErr, pictPath)
|
|
})
|
|
});
|
|
})
|
|
}
|
|
});
|
|
}
|
|
})
|
|
}
|
|
|
|
module.exports = function(pConfig) {
|
|
BOB_cfg_config = pConfig;
|
|
return BOB_module;
|
|
}
|