@shibam/sticker-maker 1.2.9 → 1.2.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shibam/sticker-maker",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -13,6 +13,6 @@
13
13
  "dependencies": {
14
14
  "file-type": "^20.0.0",
15
15
  "node-webpmux": "^3.2.0",
16
- "sharp": "^0.33.5"
16
+ "sharp": "0.30.0"
17
17
  }
18
18
  }
@@ -26,17 +26,17 @@ class Exif {
26
26
  }
27
27
 
28
28
  async add(image) {
29
- const exif = this.exif || this.build();
30
-
31
- if (image instanceof Image.Image) {
32
- image.exif = exif;
33
- return await image.save(null);
34
- }
35
-
36
- const img = new Image.Image();
37
- await img.load(image);
38
- img.exif = exif;
39
- return await img.save(null);
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
@@ -19,7 +19,7 @@ export default class MediaConverter {
19
19
  async convertToWebp(buffer) {
20
20
  const fileType = await fileTypeFromBuffer(buffer);
21
21
  if (!fileType) throw new Error("Invalid file type");
22
-
22
+ if (fileType.ext === "webp") return buffer;
23
23
  this.mime = fileType.mime;
24
24
 
25
25
  if (this.mime.startsWith("video/")) {
@@ -46,11 +46,17 @@ export default class MediaConverter {
46
46
 
47
47
  const gifBuffer = await fs.readFile(tempOutput);
48
48
 
49
- await Promise.all([fs.unlink(tempInput).catch(() => {}), fs.unlink(tempOutput).catch(() => {})]);
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([fs.unlink(tempInput).catch(() => {}), fs.unlink(tempOutput).catch(() => {})]);
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
  }
@@ -63,12 +69,16 @@ export default class MediaConverter {
63
69
  const isAnimated = mimeType?.includes("video") || mimeType?.includes("gif");
64
70
 
65
71
  // Initialize sharp with animation support for GIFs or video frames
66
- const res = sharp(buffer, { animated: isAnimated });
67
-
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
+ });
68
78
  // Convert to WebP format with the specified quality
79
+
69
80
  return await res
70
- .toFormat("webp")
71
- .webp({ quality: this.quality, lossless: isAnimated }) // Lossless for GIFs or animations
81
+ .webp({ quality: this.quality, lossless: false }) // Lossless for GIFs or animations
72
82
  .toBuffer();
73
83
  }
74
84
  }