@shibam/sticker-maker 1.2.8 → 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/package.json +1 -1
- package/utils/convert.js +3 -7
package/package.json
CHANGED
package/utils/convert.js
CHANGED
|
@@ -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")
|