bug fix
@ -0,0 +1,25 @@
|
||||
var qrDecode = require('./')
|
||||
|
||||
var decode =
|
||||
exports.decode = function (bom) {
|
||||
var canvas = document.createElement("canvas")
|
||||
var ctx = canvas.getContext('2d')
|
||||
canvas.width = bom.width;
|
||||
canvas.height = bom.height;
|
||||
ctx.drawImage(bom, 0, 0, canvas.width, canvas.height);
|
||||
var data = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
return qrDecode(data)
|
||||
}
|
||||
|
||||
exports.decodeByUrl = function (src, cb) {
|
||||
var img = new Image();
|
||||
img.src = src;
|
||||
img.onload = function () {
|
||||
try {
|
||||
cb(null,decode(img));
|
||||
} catch (e) {
|
||||
cb(e);
|
||||
}
|
||||
}
|
||||
img.onerror = cb;
|
||||
}
|
After Width: | Height: | Size: 188 KiB |
Before Width: | Height: | Size: 282 KiB After Width: | Height: | Size: 282 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 375 KiB |
After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 100 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 1.1 MiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 35 KiB |
Before Width: | Height: | Size: 67 KiB |
Before Width: | Height: | Size: 50 KiB |
Before Width: | Height: | Size: 7.9 KiB |
Before Width: | Height: | Size: 282 KiB |
Before Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 36 KiB |
@ -1,12 +1,23 @@
|
||||
var imgDecode = require('../server')
|
||||
var path = require('path');
|
||||
var dir = __dirname;
|
||||
// console.log(path);
|
||||
var P = function (p) {
|
||||
return path.join(__dirname, p);
|
||||
}
|
||||
|
||||
|
||||
imgDecode.decodeQRFile('./img/out.bmp').then(console.log)
|
||||
imgDecode.decodeQRFile('./img/out.jpg').then(console.log,console.error)
|
||||
imgDecode.decodeQRFile('./img/out.png').then(console.log,console.error)
|
||||
imgDecode.decodeQRFile('./img/out.gif').then(console.log,console.error)
|
||||
imgDecode.decodeQRFile('./img/dt.gif').then(console.log,console.error)
|
||||
imgDecode.decodeQRFile('./img/dt1.gif').then(console.log,console.error)
|
||||
|
||||
//动态img
|
||||
var test = function (path, mark) {
|
||||
return imgDecode.decodeByPath(P(path))
|
||||
.then(console.log.bind(console, mark + ': '), console.error.bind(console, mark + ':'))
|
||||
}
|
||||
Promise.resolve()
|
||||
.then(function () { test('./img/16.bmp', 'bmp16 ') })
|
||||
.then(function () { return test('./img/24.bmp', 'bmp24 ') })
|
||||
.then(function () { return test('./img/32.bmp', 'bmp32 ') })
|
||||
.then(function () { return test('/img/lx.jpg', 'jpg_lx') }) //jpg 连续
|
||||
.then(function () { return test('/img/yh.jpg', 'jpg_yh') }) //jpg 优化
|
||||
.then(function () { return test('./img/8.png', 'png8 ') })
|
||||
.then(function () { return test('./img/24.png', 'png24 ') })
|
||||
.then(function () { return test('./img/jt.gif', 'gif_jt') }) //单帧
|
||||
.then(function () { return test('./img/dt.gif', 'gif_dt') }) //多帧
|
||||
|
||||
|