@shibam/sticker-maker 1.2.8 → 1.2.10
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/package.json +1 -1
- package/utils/changeMetaInfo.js +11 -11
- package/utils/convert.js +19 -13
package/package.json
CHANGED
package/utils/changeMetaInfo.js
CHANGED
|
@@ -26,17 +26,17 @@ class Exif {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async add(image) {
|
|
29
|
-
const exif = this.exif || this.build()
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return await
|
|
29
|
+
const exif = this.exif || this.build()
|
|
30
|
+
image =
|
|
31
|
+
image instanceof Image.Image
|
|
32
|
+
? image
|
|
33
|
+
: await (async () => {
|
|
34
|
+
const img = new Image.Image()
|
|
35
|
+
await img.load(image)
|
|
36
|
+
return img
|
|
37
|
+
})();
|
|
38
|
+
image.exif = exif
|
|
39
|
+
return await image.save(null)
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
package/utils/convert.js
CHANGED
|
@@ -46,33 +46,39 @@ export default class MediaConverter {
|
|
|
46
46
|
|
|
47
47
|
const gifBuffer = await fs.readFile(tempOutput);
|
|
48
48
|
|
|
49
|
-
await Promise.all([
|
|
49
|
+
await Promise.all([
|
|
50
|
+
fs.unlink(tempInput).catch(() => {}),
|
|
51
|
+
fs.unlink(tempOutput).catch(() => {}),
|
|
52
|
+
]);
|
|
50
53
|
|
|
51
54
|
return gifBuffer;
|
|
52
55
|
} catch (error) {
|
|
53
|
-
await Promise.all([
|
|
56
|
+
await Promise.all([
|
|
57
|
+
fs.unlink(tempInput).catch(() => {}),
|
|
58
|
+
fs.unlink(tempOutput).catch(() => {}),
|
|
59
|
+
]);
|
|
54
60
|
throw new Error(`Failed to convert video to gif: ${error.message}`);
|
|
55
61
|
}
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
async ToWebp(buffer) {
|
|
65
|
+
const fileType = await fileTypeFromBuffer(buffer);
|
|
66
|
+
if (!fileType) throw new Error("Invalid file type");
|
|
59
67
|
|
|
60
|
-
const mimeType =
|
|
68
|
+
const mimeType = fileType.mime;
|
|
61
69
|
const isAnimated = mimeType?.includes("video") || mimeType?.includes("gif");
|
|
62
70
|
|
|
63
71
|
// Initialize sharp with animation support for GIFs or video frames
|
|
64
|
-
const res = sharp(buffer, { animated: isAnimated })
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
+
const res = sharp(buffer, { animated: isAnimated })
|
|
73
|
+
.toFormat("webp")
|
|
74
|
+
.resize(this.width, this.width, {
|
|
75
|
+
fit: sharp.fit.contain,
|
|
76
|
+
background: { r: 0, g: 0, b: 0, alpha: 0 }, // Transparent background
|
|
77
|
+
});
|
|
72
78
|
// Convert to WebP format with the specified quality
|
|
79
|
+
|
|
73
80
|
return await res
|
|
74
|
-
.
|
|
75
|
-
.webp({ quality: this.quality, lossless: isAnimated }) // Lossless for GIFs or animations
|
|
81
|
+
.webp({ quality: this.quality, lossless: false }) // Lossless for GIFs or animations
|
|
76
82
|
.toBuffer();
|
|
77
83
|
}
|
|
78
84
|
}
|