@shibam/sticker-maker 1.2.10 → 1.2.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import Exif from "./utils/changeMetaInfo.js";
2
2
  import MediaConverter from "./utils/convert.js";
3
3
  import extractMetadata from "./utils/extractMetaInfo.js";
4
- import * as fs from "fs";
4
+ import fs from "fs-extra";
5
5
  import { Readable } from "stream";
6
6
 
7
7
  export default class Sticker {
@@ -36,7 +36,7 @@ export default class Sticker {
36
36
  }
37
37
 
38
38
  try {
39
- return await fs.promises.readFile(image);
39
+ return await fs.readFile(image);
40
40
  } catch (error) {
41
41
  throw new Error("Failed to read image file: " + error.message);
42
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shibam/sticker-maker",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -12,7 +12,8 @@
12
12
  "description": "",
13
13
  "dependencies": {
14
14
  "file-type": "^20.0.0",
15
- "node-webpmux": "^3.2.0",
16
- "sharp": "^0.33.5"
15
+ "fs-extra": "^11.3.0",
16
+ "node-webpmux": "3.1.0",
17
+ "sharp": "0.30.0"
17
18
  }
18
19
  }
package/utils/convert.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import { exec as execCallback } from "child_process";
2
- import { promisify } from "util";
3
- import { promises as fs } from "fs";
2
+ import { writeFile, readFile, unlink } from "fs-extra";
4
3
  import { tmpdir } from "os";
5
- import { join } from "path";
4
+ import { promisify } from "util";
6
5
  import { fileTypeFromBuffer } from "file-type";
7
6
  import sharp from "sharp";
8
7
 
@@ -19,7 +18,7 @@ export default class MediaConverter {
19
18
  async convertToWebp(buffer) {
20
19
  const fileType = await fileTypeFromBuffer(buffer);
21
20
  if (!fileType) throw new Error("Invalid file type");
22
-
21
+ if (fileType.ext === "webp") return buffer;
23
22
  this.mime = fileType.mime;
24
23
 
25
24
  if (this.mime.startsWith("video/")) {
@@ -34,33 +33,32 @@ export default class MediaConverter {
34
33
  throw new Error(`Unsupported file type: ${this.mime}`);
35
34
  }
36
35
 
37
- async videoToGif(buffer) {
38
- const tempInput = join(tmpdir(), `input_${Date.now()}.mp4`);
39
- const tempOutput = join(tmpdir(), `output_${Date.now()}.gif`);
40
-
36
+ videoToGif = async (data) => {
37
+ const filename = `${tmpdir()}/${Math.random().toString(36).substring(2)}`;
38
+ const videoPath = `${filename}.mp4`;
39
+ const gifPath = `${filename}.gif`;
40
+
41
41
  try {
42
- await fs.writeFile(tempInput, buffer);
43
-
44
- const ffmpegCmd = `ffmpeg -i "${tempInput}" -vf "fps=${this.fps},scale=${this.width}:-1:flags=lanczos" -loop 0 -lossless 0 -t 7 -preset ultrafast -f gif "${tempOutput}"`;
42
+ // Write the input video buffer to a temporary file
43
+ await writeFile(videoPath, data);
44
+
45
+ // Execute FFmpeg command to convert video to GIF with lossless option
46
+ const ffmpegCmd = `ffmpeg -i "${videoPath}" -vf "fps=15,scale=320:-1:flags=lanczos" -loop 0 -lossless 0 "${gifPath}"`;
45
47
  await exec(ffmpegCmd);
46
-
47
- const gifBuffer = await fs.readFile(tempOutput);
48
-
49
- await Promise.all([
50
- fs.unlink(tempInput).catch(() => {}),
51
- fs.unlink(tempOutput).catch(() => {}),
52
- ]);
53
-
48
+
49
+ // Read the resulting GIF as a buffer
50
+ const gifBuffer = await readFile(gifPath);
51
+
52
+ // Clean up temporary files
53
+ await Promise.all([unlink(videoPath).catch(() => {}), unlink(gifPath).catch(() => {})]);
54
+
54
55
  return gifBuffer;
55
56
  } catch (error) {
56
- await Promise.all([
57
- fs.unlink(tempInput).catch(() => {}),
58
- fs.unlink(tempOutput).catch(() => {}),
59
- ]);
60
- throw new Error(`Failed to convert video to gif: ${error.message}`);
57
+ // Clean up files in case of an error
58
+ await Promise.all([unlink(videoPath).catch(() => {}), unlink(gifPath).catch(() => {})]);
59
+ throw new Error(`Failed to convert video to GIF: ${error.message}`);
61
60
  }
62
- }
63
-
61
+ };
64
62
  async ToWebp(buffer) {
65
63
  const fileType = await fileTypeFromBuffer(buffer);
66
64
  if (!fileType) throw new Error("Invalid file type");