@realvare/based 2.6.24 → 2.6.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Utils/messages-media.js +4 -16
- package/lib/Utils/thumbnail.js +10 -27
- package/package.json +2 -9
|
@@ -63,22 +63,10 @@ const crypto_1 = require("./crypto");
|
|
|
63
63
|
const generics_1 = require("./generics");
|
|
64
64
|
const getTmpFilesDirectory = () => (0, os_1.tmpdir)();
|
|
65
65
|
const getImageProcessingLibrary = async () => {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
})(),
|
|
71
|
-
(async () => {
|
|
72
|
-
const sharp = await (Promise.resolve().then(() => __importStar(require('sharp'))).catch(() => { }));
|
|
73
|
-
return sharp;
|
|
74
|
-
})()
|
|
75
|
-
]);
|
|
76
|
-
if (sharp) {
|
|
77
|
-
return { sharp };
|
|
78
|
-
}
|
|
79
|
-
const jimp = (_jimp === null || _jimp === void 0 ? void 0 : _jimp.default) || _jimp;
|
|
80
|
-
if (jimp) {
|
|
81
|
-
return { jimp };
|
|
66
|
+
const jimp = await (Promise.resolve().then(() => __importStar(require('jimp'))).catch(() => { }));
|
|
67
|
+
const jimpLib = (jimp === null || jimp === void 0 ? void 0 : jimp.default) || jimp;
|
|
68
|
+
if (jimpLib) {
|
|
69
|
+
return { jimp: jimpLib };
|
|
82
70
|
}
|
|
83
71
|
throw new boom_1.Boom('No image processing library available');
|
|
84
72
|
};
|
package/lib/Utils/thumbnail.js
CHANGED
|
@@ -1,35 +1,18 @@
|
|
|
1
|
-
const
|
|
2
|
-
const fs = require('fs/promises');
|
|
3
|
-
const fetch = require('node-fetch');
|
|
1
|
+
const Jimp = require('jimp');
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
* Generates
|
|
4
|
+
* Generates a high-quality JPEG thumbnail buffer for externalAdReply.
|
|
7
5
|
* @param {string | Buffer} imagePathOrBuffer - Path to image file, Buffer, or URL.
|
|
8
6
|
* @param {number} [size=150] - Target square size (default 150 for balance between quality and load time).
|
|
9
|
-
* @param {number} [quality=
|
|
10
|
-
* @returns {Promise<Buffer>} -
|
|
7
|
+
* @param {number} [quality=100] - JPEG quality (1-100, default 100 for maximum quality).
|
|
8
|
+
* @returns {Promise<Buffer>} - High-quality thumbnail buffer.
|
|
11
9
|
*/
|
|
12
|
-
async function generateThumbnail(imagePathOrBuffer, size = 150, quality =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const response = await fetch(imagePathOrBuffer);
|
|
19
|
-
input = Buffer.from(await response.arrayBuffer());
|
|
20
|
-
} else {
|
|
21
|
-
// Local file
|
|
22
|
-
input = await fs.readFile(imagePathOrBuffer);
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
input = imagePathOrBuffer;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return sharp(input)
|
|
29
|
-
.resize(size, size, { fit: 'cover', kernel: sharp.kernel.lanczos3 }) // Lanczos for sharp resizing
|
|
30
|
-
.sharpen() // Optional: Adds slight sharpness to counter blurring
|
|
31
|
-
.jpeg({ quality, mozjpeg: true }) // Use high-quality JPEG compression
|
|
32
|
-
.toBuffer();
|
|
10
|
+
async function generateThumbnail(imagePathOrBuffer, size = 150, quality = 100) {
|
|
11
|
+
const image = await Jimp.read(imagePathOrBuffer);
|
|
12
|
+
return image
|
|
13
|
+
.cover(size, size) // Cover fit for square thumbnail
|
|
14
|
+
.quality(quality) // Set JPEG quality
|
|
15
|
+
.getBufferAsync(Jimp.MIME_JPEG);
|
|
33
16
|
}
|
|
34
17
|
|
|
35
18
|
module.exports = { generateThumbnail };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@realvare/based",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.25",
|
|
4
4
|
"description": "WhatsApp Web API by Sam",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"baileys",
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
"music-metadata": "^7.12.3",
|
|
59
59
|
"pino": "^9.6",
|
|
60
60
|
"protobufjs": "^7.2.5",
|
|
61
|
-
"sharp": "^0.33.5",
|
|
62
61
|
"uuid": "^10.0.0",
|
|
63
62
|
"ws": "^8.18.0"
|
|
64
63
|
},
|
|
@@ -67,7 +66,6 @@
|
|
|
67
66
|
"@types/got": "^9.6.11",
|
|
68
67
|
"@types/jest": "^29.5.12",
|
|
69
68
|
"@types/node": "^20.14.0",
|
|
70
|
-
"@types/sharp": "^0.32.0",
|
|
71
69
|
"@types/ws": "^8.5.10",
|
|
72
70
|
"conventional-changelog-cli": "^2.2.2",
|
|
73
71
|
"eslint": "^8.57.0",
|
|
@@ -78,7 +76,6 @@
|
|
|
78
76
|
"open": "^10.1.0",
|
|
79
77
|
"qrcode-terminal": "^0.12.0",
|
|
80
78
|
"release-it": "^16.1.0",
|
|
81
|
-
"sharp": "^0.33.5",
|
|
82
79
|
"ts-jest": "^29.1.2",
|
|
83
80
|
"ts-node": "^10.9.2",
|
|
84
81
|
"typedoc": "^0.25.12",
|
|
@@ -87,8 +84,7 @@
|
|
|
87
84
|
"peerDependencies": {
|
|
88
85
|
"audio-decode": "^2.1.3",
|
|
89
86
|
"link-preview-js": "^3.0.0",
|
|
90
|
-
"qrcode-terminal": "^0.12.0"
|
|
91
|
-
"sharp": "^0.33.0"
|
|
87
|
+
"qrcode-terminal": "^0.12.0"
|
|
92
88
|
},
|
|
93
89
|
"peerDependenciesMeta": {
|
|
94
90
|
"audio-decode": {
|
|
@@ -97,9 +93,6 @@
|
|
|
97
93
|
"jimp": {
|
|
98
94
|
"optional": true
|
|
99
95
|
},
|
|
100
|
-
"sharp": {
|
|
101
|
-
"optional": true
|
|
102
|
-
},
|
|
103
96
|
"link-preview-js": {
|
|
104
97
|
"optional": true
|
|
105
98
|
}
|