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 { console.log(list) 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 pbltPath = BOB_mod_path.join(BOB_cfg_config.paths.prebuilt, pBoothId); var pictOrig = BOB_mod_path.join(destPath, BOB_cfg_config.pictNames[pPictId]); var pictPblt = BOB_mod_path.join(destPath, BOB_cfg_config.pictNames[pPictId]); BOB_mod_mkdirp.sync(BOB_mod_path.join(BOB_cfg_config.paths.prebuilt, pBoothId)); 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(pictOrig, pData, function(pErr) { // BOB_mod_gm(pictOrig) // .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(pictOrig, function(pErr) { // return pCallback(pErr, pictPblt) // }) return pCallback(pErr, pictOrig) }); }) } }); } }) } module.exports = function(pConfig) { BOB_cfg_config = pConfig; return BOB_module; }