2025/2/8第一次更新

This commit is contained in:
爱吃咸鱼小猫咪
2025-02-08 18:50:38 +08:00
commit d7af560866
26519 changed files with 5046029 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
module.exports = {
env: {
"mocha": true,
},
};
Binary file not shown.

After

Width:  |  Height:  |  Size: 971 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 845 B

+151
View File
@@ -0,0 +1,151 @@
var expect = require('chai').expect;
var fs = require('fs');
var QrCode = require('../dist/index.js');
var ImageParser = require("image-parser");
const Jimp = require("jimp");
const expectedResult = {
"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,
}
]
};
function copy(input) {
return JSON.parse(JSON.stringify(input));
}
it("should work with jimp", function(done) {
var buffer = fs.readFileSync(__dirname + '/image.png');
Jimp.read(buffer, function(err, image) {
if (err) {
return done(err);
}
var qr = new QrCode();
qr.callback = function(err, result) {
if (err) {
return done(err);
}
expect(copy(result)).to.deep.equal(expectedResult);
done();
};
qr.decode(image.bitmap);
});
});
it("should work with a zxing qr code with jimp", function(done) {
var buffer = fs.readFileSync(__dirname + '/image-zxing.png');
Jimp.read(buffer, function(err, image) {
if (err) {
return done(err);
}
var qr = new QrCode();
qr.callback = function(err, result) {
if (err) {
return done(err);
}
expect(copy(result)).to.deep.equal({
"result": 'Test',
"points": [
{
"count": 2,
"estimatedModuleSize": 9,
"x": 34.5,
"y": 160.5,
},
{
"count": 3,
"estimatedModuleSize": 9,
"x": 34.5,
"y": 34.5,
},
{
"count": 2,
"estimatedModuleSize": 9.428571428571429,
"x": 160.5,
"y": 34.5,
}
]
});
done();
};
qr.decode(image.bitmap);
});
});
it('should work with basic image', function(done) {
var buffer = fs.readFileSync(__dirname + '/image.png');
var img = new ImageParser(buffer);
img.parse(function(err) {
if (err) {
return done(err);
}
var qr = new QrCode();
qr.callback = function(err, result) {
if (err) {
return done(err);
}
expect(copy(result)).to.deep.equal(expectedResult);
done();
};
qr.decode({width: img.width(), height: img.height()}, img._imgBuffer);
});
});
it('should work with imageData format', function(done) {
var buffer = fs.readFileSync(__dirname + '/image.png');
var img = new ImageParser(buffer);
img.parse(function(err) {
if (err) {
return done(err);
}
var qr = new QrCode();
qr.callback = function(err, result) {
if (err) {
return done(err);
}
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});
});
});