@shibam/sticker-maker 1.2.7 → 1.2.9
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/index.js +6 -9
- package/package.json +2 -5
- package/utils/convert.js +6 -10
package/index.js
CHANGED
|
@@ -98,13 +98,10 @@ export default class Sticker {
|
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
async build() {
|
|
101
|
-
// Process input to buffer
|
|
102
101
|
const inputBuffer = await this.processImage(this.image);
|
|
103
102
|
|
|
104
|
-
// Convert to WebP using imported converter
|
|
105
103
|
const webpBuffer = await this.converter.convertToWebp(inputBuffer);
|
|
106
104
|
|
|
107
|
-
// Add metadata using imported Exif handler
|
|
108
105
|
const exif = new Exif({
|
|
109
106
|
id: this.id,
|
|
110
107
|
pack: this.pack,
|
|
@@ -120,11 +117,11 @@ export default class Sticker {
|
|
|
120
117
|
return await this.build();
|
|
121
118
|
}
|
|
122
119
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return await extractMetadata(this.buffer);
|
|
120
|
+
async metadata() {
|
|
121
|
+
if (!this.buffer) {
|
|
122
|
+
await this.build();
|
|
129
123
|
}
|
|
124
|
+
|
|
125
|
+
return await extractMetadata(this.buffer);
|
|
126
|
+
}
|
|
130
127
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shibam/sticker-maker",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -11,11 +11,8 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"description": "",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"cwebp": "^3.1.0",
|
|
15
14
|
"file-type": "^20.0.0",
|
|
16
|
-
"jimp": "^1.6.0",
|
|
17
15
|
"node-webpmux": "^3.2.0",
|
|
18
|
-
"sharp": "0.
|
|
19
|
-
"webp-converter": "^2.3.3"
|
|
16
|
+
"sharp": "^0.33.5"
|
|
20
17
|
}
|
|
21
18
|
}
|
package/utils/convert.js
CHANGED
|
@@ -10,9 +10,9 @@ const exec = promisify(execCallback);
|
|
|
10
10
|
|
|
11
11
|
export default class MediaConverter {
|
|
12
12
|
constructor(options = {}) {
|
|
13
|
-
this.fps =
|
|
14
|
-
this.quality = options.quality
|
|
15
|
-
this.width = options.width
|
|
13
|
+
this.fps = 12;
|
|
14
|
+
this.quality = options.quality ?? 10;
|
|
15
|
+
this.width = options.width ?? 320;
|
|
16
16
|
this.mime = null;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -56,19 +56,15 @@ export default class MediaConverter {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async ToWebp(buffer) {
|
|
59
|
+
const fileType = await fileTypeFromBuffer(buffer);
|
|
60
|
+
if (!fileType) throw new Error("Invalid file type");
|
|
59
61
|
|
|
60
|
-
const mimeType =
|
|
62
|
+
const mimeType = fileType.mime;
|
|
61
63
|
const isAnimated = mimeType?.includes("video") || mimeType?.includes("gif");
|
|
62
64
|
|
|
63
65
|
// Initialize sharp with animation support for GIFs or video frames
|
|
64
66
|
const res = sharp(buffer, { animated: isAnimated });
|
|
65
67
|
|
|
66
|
-
// Resize image to fit within the specified width while preserving aspect ratio
|
|
67
|
-
res.resize(this.width, this.width, {
|
|
68
|
-
fit: sharp.fit.contain,
|
|
69
|
-
background: { r: 0, g: 0, b: 0, alpha: 0 }, // Transparent background
|
|
70
|
-
});
|
|
71
|
-
|
|
72
68
|
// Convert to WebP format with the specified quality
|
|
73
69
|
return await res
|
|
74
70
|
.toFormat("webp")
|