diff --git a/CHANGELOG.md b/CHANGELOG.md index 602f5f6..5299a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,15 +1,19 @@ -# Changelog +Changelog +========= All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## 1.0.0 - 2016-12-14 +1.0.0 [unreleased] +------------------ ### Changed -* Update api to be error-first ([#30](https://github.com/edi9999/jsqrcode/pull/30)) +- Update api to return result and bounding box : https://github.com/edi9999/jsqrcode/issues/35 +- Update api to be error-first ([#30](https://github.com/edi9999/jsqrcode/pull/30)\) -## 0.x +0.x +--- -* Initial release +- Initial release diff --git a/README.md b/README.md index c8541ad..fcc63c9 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,6 @@ var data = context.getImageData(0, 0, width, height); qr.decode(data); ``` -Decode from canvas with "qr-canvas" ID: - -``` -qr.decode() -``` - -Building it yourself ==================== If you want, you can build the script yourself. @@ -97,6 +90,6 @@ You will have access to the global variable `QrCode` if you do the following in See [examples/browser-upload/index.html](examples/browser-upload/index.html) for a very basic example using a file upload. Changelog -=========================== +========= -See [`CHANGELOG.md`](CHANGELOG.md). +See [`CHANGELOG.md`](CHANGELOG.md)\. diff --git a/package.json b/package.json index 09414cf..69ea042 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,10 @@ }, "homepage": "https://github.com/edi9999/jsqrcode", "devDependencies": { - "chai": "^1.9.1", + "chai": "^3.5.0", "eslint": "^2.13.1", - "mocha": "^2.4.5", "image-parser": "^1.2.4", + "mocha": "^3.2.0", "rollup": "^0.34.13", "uglify-js": "^2.7.3" } diff --git a/src/qrcode.js b/src/qrcode.js index 76f3d87..9f4bfd5 100644 --- a/src/qrcode.js +++ b/src/qrcode.js @@ -52,20 +52,8 @@ QrCode.prototype.decode = function(src, data) { }).bind(this); - if (src == undefined) { - /* decode from canvas #qr-canvas */ - - var canvas_qr = document.getElementById("qr-canvas"); - var context = canvas_qr.getContext('2d'); - - this.width = canvas_qr.width; - this.height = canvas_qr.height; - this.imagedata = context.getImageData(0, 0, this.width, this.height); - - decode(); - } else if (src.width != undefined) { + if (src != undefined && src.width != undefined) { /* decode from canvas canvas.context.getImageData */ - this.width = src.width; this.height = src.height; this.imagedata = {"data": data || src.data}; @@ -153,7 +141,7 @@ QrCode.prototype.process = function(imageData) { console.log('QR Code processing time (ms): ' + time); } - return this.decode_utf8(str); + return {result: this.decode_utf8(str), points: qRCodeMatrix.points}; }; QrCode.prototype.getPixel = function(imageData, x, y) { diff --git a/test/qrcode.js b/test/qrcode.js index 0c41a19..22fbd11 100644 --- a/test/qrcode.js +++ b/test/qrcode.js @@ -3,6 +3,10 @@ var fs = require('fs'); var QrCode = require('../dist/index.js'); var ImageParser = require("image-parser"); +function copy(input) { + return JSON.parse(JSON.stringify(input)); +} + it('should work with basic image', function(done) { var c = fs.readFileSync(__dirname + '/image.png'); var img = new ImageParser(c); @@ -13,9 +17,31 @@ it('should work with basic image', function(done) { var qr = new QrCode(); qr.callback = function(error, result) { if (error) { - done(error); + return done(error); } - expect(result).to.equal('Test'); + expect(copy(result)).to.deep.equal({ + "result": 'Test', + "points": [ + { + "count": 2, + "estimatedModuleSize": 8, + "x": 36, + "y": 148, + }, + { + "count": 2, + "estimatedModuleSize": 8, + "x": 36, + "y": 36, + }, + { + "count": 2, + "estimatedModuleSize": 8, + "x": 148, + "y": 36, + } + ] + }); done(); }; qr.decode({width: img.width(), height: img.height()}, img._imgBuffer); @@ -32,15 +58,33 @@ it('should work with imageData format', function(done) { var qr = new QrCode(); qr.callback = function(error, result) { if (error) { - done(error); + return done(error); } - expect(result).to.equal('Test'); + expect(copy(result)).to.deep.equal({ + "result": 'Test', + "points": [ + { + "count": 2, + "estimatedModuleSize": 8, + "x": 36, + "y": 148, + }, + { + "count": 2, + "estimatedModuleSize": 8, + "x": 36, + "y": 36, + }, + { + "count": 2, + "estimatedModuleSize": 8, + "x": 148, + "y": 36, + } + ] + }); done(); }; - qr.decode({ - height: img.height(), - width: img.width(), - data: img._imgBuffer - }); + qr.decode({height: img.height(), width: img.width(), data: img._imgBuffer}); }); });