├── .gitignore ├── .nodemonignore ├── Makefile ├── README.md ├── index.js ├── lib └── detector.js ├── package.json └── test ├── detector.test.js └── example.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Node.js with Express and Stlyus 2 | public/css/*.css 3 | public/css/main/*.css 4 | public/css/admin/*.css 5 | /.monitor 6 | 7 | /log 8 | /data 9 | /cache 10 | 11 | /public/js/compact 12 | 13 | # Windows 14 | Thumbs.db 15 | 16 | # Vim 17 | .*.sw[a-z] 18 | *.un~i 19 | tags 20 | 21 | # OsX 22 | .DS_Store 23 | Icon? 24 | ._* 25 | .Spotlight-V100 26 | .Trashes 27 | 28 | # nodejs npm modules 29 | node_modules 30 | 31 | # node-cluster 32 | /pids 33 | *.sock 34 | 35 | # ZSH Cake plugin cache 36 | /.cake_task_cache -------------------------------------------------------------------------------- /.nodemonignore: -------------------------------------------------------------------------------- 1 | public/css/* 2 | public/fonts/* 3 | public/images/* 4 | public/js/compact/* 5 | views/* -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | @./node_modules/.bin/mocha \ 3 | -r should \ 4 | -R spec 5 | 6 | lint-changed: 7 | @jshint `git status --porcelain | sed -e "s/^...//g"` 8 | 9 | lint: 10 | @jshint lib test 11 | 12 | .PHONY: test lint lint-changed -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Node ZBar 2 | 3 | node-zbar is a NodeJS binding to the ZBar QR Code library. Initially this will spawn a child process and monitor the output. But eventually it will be a C++ module. 4 | 5 | ## Installation 6 | 7 | To use node-zbar, you will install the prerequisite of ZBar. 8 | 9 | Compile from source see 10 | 11 | http://zbar.sourceforge.net/ 12 | 13 | Node-zbar can then be installed via NPM 14 | 15 | npm install zbar 16 | 17 | 18 | Then, require the module 19 | 20 | var zbar = require('zbar'); 21 | 22 | 23 | ## Usage 24 | ```js 25 | var Zbar = require('zbar'); 26 | 27 | zbar = new Zbar(device[, options]); 28 | 29 | 30 | zbar.stdout.on('data', function(buf) { 31 | console.log('data scanned : ' + buf.toString()); 32 | }); 33 | 34 | zbar.stderr.on('data', function(buf) { 35 | console.log(buf.toString()); 36 | }); 37 | ``` 38 | 39 | Watch for data on device. `device` is a path to a supported webcam device. For example `/dev/video0` 40 | 41 | The second argument is optional. The options if provided should be an object. The list of available options are as following: 42 | 43 | `width` - scale the width of the sampled image 44 | 45 | `height` - scale the width of the sampled image 46 | 47 | `dataType` - can be `raw` or `xml`. default is `raw` 48 | 49 | You should watch the `stdout` and `stderr` data. 50 | 51 | Example: 52 | ```js 53 | var Zbar = require('zbar'); 54 | 55 | zbar = new Zbar('/dev/video0'); 56 | 57 | 58 | zbar.stdout.on('data', function(buf) { 59 | console.log('data scanned : ' + buf.toString()); 60 | }); 61 | 62 | zbar.stderr.on('data', function(buf) { 63 | console.log(buf.toString()); 64 | }); 65 | ``` 66 | 67 | ## Licence 68 | Licensed under the [New BSD License](http://opensource.org/licenses/bsd-license.php) 69 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = require('./lib/detector').createWatcher; -------------------------------------------------------------------------------- /lib/detector.js: -------------------------------------------------------------------------------- 1 | var child_process = require('child_process') 2 | ; 3 | 4 | module.exports.createWatcher = function(device, options) { 5 | 6 | options = options || {}; 7 | options.dataType = options.dataType || 'raw'; 8 | options.width = options.width || 800; 9 | options.height = options.height || 600; 10 | options.whiteList = options.whiteList || false; // when true used in conjunction with symbology to whitelist single symbologies 11 | options.symbology = options.symbology || false; // array of options eg: [ 'qrcode.enable', 'isbn13.disable' ] 12 | 13 | if (options.whiteList) { 14 | zbarArguments.push('-Sdisable'); 15 | } 16 | 17 | if (Array.isArray(options.symbology)) { 18 | for (var i = 0; i < options.symbology.length; i++) { 19 | zbarArguments.push('-S' + options.symbology[i]); 20 | } 21 | } 22 | 23 | if (options.height / options.width !== 0.75) { 24 | throw new Error('Aspect ratio must be 4:3'); 25 | } 26 | 27 | var zbarArguments = 28 | [ '--prescale=' + options.width + 'x' + options.height 29 | , '--nodisplay' 30 | ] 31 | , zbar 32 | ; 33 | 34 | // Push data type onto arguments 35 | zbarArguments.push((options.dataType === 'xml') ? '--xml' : '--' + options.dataType); 36 | 37 | // add device as last element 38 | zbarArguments.push(device); 39 | 40 | // spawn the child process 41 | zbar = child_process.spawn('zbarcam' 42 | , zbarArguments 43 | ); 44 | 45 | return zbar; 46 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zbar", 3 | "author": "Tom Gallacher", 4 | "description": "node-zbar is a NodeJS binding to the ZBar QR Code library.", 5 | "repository": { 6 | "type": "git", 7 | "url": "git://github.com/tomgco/node-zbar.git" 8 | }, 9 | "keywords": [ 10 | "qrcode", 11 | "qr", 12 | "scan" 13 | ], 14 | "version": "0.0.4", 15 | "engine": "~0.6", 16 | "dependencies": {}, 17 | "devDependencies": { 18 | "mocha": "*", 19 | "should": "*" 20 | }, 21 | "optionalDependencies": {}, 22 | "engines": { 23 | "node": "*" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /test/detector.test.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomgco/node-zbar/d0e0c28e0fa58128a0d2f4a1c7d6fc7ac4c778df/test/detector.test.js -------------------------------------------------------------------------------- /test/example.js: -------------------------------------------------------------------------------- 1 | var Zbar = require('../zbar') 2 | , zbar = new Zbar('/dev/video0') 3 | ; 4 | 5 | zbar.on('data', function(buf) { 6 | console.log(buf.toString()); 7 | }); 8 | 9 | zbar.on('error', function(buf) { 10 | console.log(buf.toString()); 11 | }); --------------------------------------------------------------------------------