@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shibam/sticker-maker",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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
@@ -46,33 +46,39 @@ 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
  }
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 = this.mime;
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
- // 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
+ 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
- .toFormat("webp")
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
  }