-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckQCode.js
More file actions
60 lines (52 loc) · 1.54 KB
/
checkQCode.js
File metadata and controls
60 lines (52 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const Jimp = require('jimp');
const jsQR = require('jsqr');
const fs = require('fs');
const rootPath = "D:/115下载/[Silver Dog] Shishou kara Osowatta Koto (Sousou no Frieren) [Chinese]"; //把父文件夹地址填充于此!
function checkFiles() {
let files = walk(rootPath);
for (let index = 0; index < files.length; index++) {
const file = files[index];
checkForQRCode(file);
}
}
function walk(dir) {
var results = [];
var list = fs.readdirSync(dir);
list.forEach(function (file) {
file = dir + '/' + file;
var stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
/* Recurse into a subdirectory */
results = results.concat(walk(file));
} else {
/* Is a file */
results.push(file);
}
});
return results;
}
async function checkForQRCode(imagePath) {
try {
const image = await Jimp.read(imagePath);
const imageWidth = image.bitmap.width;
const imageHeight = image.bitmap.height;
const imageData = new Uint8ClampedArray(image.bitmap.data.buffer);
// 使用 jsQR 来检测图像中的二维码
const qrCode = jsQR(imageData, imageWidth, imageHeight);
if (qrCode) {
if (qrCode.data.indexOf('http') > -1) {
console.log(imagePath + '二维码检测到:', qrCode.data);
return true
} else {
return false
}
} else {
console.log('未检测到二维码');
return false; // 不存在二维码
}
} catch (error) {
console.error('检测二维码时发生错误:', error);
return false;
}
}
checkFiles()