| Hash | Commit message | Author | Date | Files | + | - |
1 | commit 91949428ee64cb35e12bb5294f4eef4b93dd4709 |
2 | Author: Connor Etherington <[email protected]> |
3 | Date: Wed Oct 25 10:14:57 2023 +0200 |
4 | |
5 | Auto-Commit Update - 20231025 |
6 | --- |
7 | PKGBUILD | 2 +- |
8 | README.md | 2 +- |
9 | usr/share/doc/lfp/README.md | 2 +- |
10 | usr/share/lfp/ocr/ocr.js | 27 +++++++++++++++++++++++++-- |
11 | usr/share/lfp/ocr/package.json | 5 ++++- |
12 | 5 files changed, 32 insertions(+), 6 deletions(-) |
13 | |
14 | diff --git a/PKGBUILD b/PKGBUILD |
15 | index ce934f6..1a051dc 100644 |
16 | --- a/PKGBUILD |
17 | +++ b/PKGBUILD |
18 | @@ -1,7 +1,7 @@ |
19 | # Maintainer: Connor Etherington <[email protected]> |
20 | # --- |
21 | pkgname=lfp |
22 | -pkgver=4.1.1 |
23 | +pkgver=4.1.2 |
24 | pkgrel=1 |
25 | pkgdesc='A wrapper for the lf file manager with in-terminal media previews, on-exit directory changing and much more' |
26 | license=('MIT') |
27 | diff --git a/README.md b/README.md |
28 | index 19fdbe8..3cd691a 100644 |
29 | --- a/README.md |
30 | +++ b/README.md |
31 | @@ -4,7 +4,7 @@ |
32 | ### `lfp` is a simple wrapper for the `lf` file manager, with built-in file, image, and video previews, as well as on-exit directory changing. |
33 | ### The program makes use of `ueberzug` to preview images, documents, and video thumbnails. Preview behavior can be altered by editing the *scope* file. |
34 | |
35 | -**Version: 4.1.1** |
36 | +**Version: 4.1.2** |
37 | |
38 | *** |
39 | |
40 | diff --git a/usr/share/doc/lfp/README.md b/usr/share/doc/lfp/README.md |
41 | index 82d6fdf..ab39372 100644 |
42 | --- a/usr/share/doc/lfp/README.md |
43 | +++ b/usr/share/doc/lfp/README.md |
44 | @@ -4,7 +4,7 @@ |
45 | ### `lfp` is a simple wrapper for the `lf` file manager, with built-in file, image, and video previews, as well as on-exit directory changing. |
46 | ### The program makes use of `ueberzug` to preview images, documents, and video thumbnails. Preview behavior can be altered by editing the *scope* file. |
47 | |
48 | -**Version: 4.1.1** |
49 | +**Version: 4.1.2** |
50 | |
51 | *** |
52 | |
53 | diff --git a/usr/share/lfp/ocr/ocr.js b/usr/share/lfp/ocr/ocr.js |
54 | index 01289b8..c87a373 100755 |
55 | --- a/usr/share/lfp/ocr/ocr.js |
56 | +++ b/usr/share/lfp/ocr/ocr.js |
57 | @@ -10,10 +10,33 @@ const green = '\x1b[32m'; |
58 | const reset = '\x1b[0m'; |
59 | |
60 | const config = { lang: 'eng', oem: 1, psm: 3 }; |
61 | +const { exec } = require('child_process'); |
62 | + |
63 | +const sh = (cmd, opts) => new Promise((resolve, reject) => { |
64 | + exec(cmd, opts, (err, stdout, stderr) => { |
65 | + if (err) { |
66 | + reject(err); |
67 | + } else { |
68 | + resolve(stdout.trim()); |
69 | + } |
70 | + }); |
71 | +}); |
72 | |
73 | const ocr = async (imagePath) => { |
74 | - const image = await fsp.readFile(imagePath); |
75 | - return tesseract.recognize(image, config); |
76 | + const Type = await sh(`file -b --mime-type ${imagePath}`); |
77 | + if (Type === 'PDF document') { |
78 | + await sh(`convert ${imagePath} -background white ${imagePath}.png`); |
79 | + const res = await tesseract.recognize(`${imagePath}.png`, config); |
80 | + await fs.unlinkSync(`${imagePath}.png`); |
81 | + return res; |
82 | + } else if(Type === 'PNG image data' || Type === 'JPEG image data' || Type === 'TIFF image data' || Type === 'image/x-portable-bitmap' || Type === 'image/png' || Type === 'image/jpeg' || Type === 'image/tiff' || Type === 'PC bitmap') { |
83 | + const image = await fsp.readFile(imagePath); |
84 | + return await tesseract.recognize(image, config); |
85 | + } else if (Type === 'Unicode text') { |
86 | + return await fsp.readFile(imagePath, 'utf8'); |
87 | + } else { |
88 | + throw new Error('Unknown image type'); |
89 | + } |
90 | } |
91 | |
92 | const args = process.argv.slice(2); |
93 | diff --git a/usr/share/lfp/ocr/package.json b/usr/share/lfp/ocr/package.json |
94 | index 9ce2737..3d887b7 100644 |
95 | --- a/usr/share/lfp/ocr/package.json |
96 | +++ b/usr/share/lfp/ocr/package.json |
97 | @@ -15,5 +15,8 @@ |
98 | "lfpreviewer" |
99 | ], |
100 | "author": "Connor Etherington <[email protected]", |
101 | - "license": "MIT" |
102 | + "license": "MIT", |
103 | + "dependencies": { |
104 | + "shx": "^0.3.4" |
105 | + } |
106 | } |