@shibam/sticker-maker 1.2.11 → 1.2.13

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.11",
3
+ "version": "1.2.13",
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",
15
+ "fs-extra": "^11.3.0",
16
+ "node-webpmux": "3.1.0",
16
17
  "sharp": "0.30.0"
17
18
  }
18
19
  }
package/utils/convert.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import { exec as execCallback } from "child_process";
2
- import { promisify } from "util";
3
- import { promises as fs } from "fs";
2
+ import fs 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
-
9
7
  const exec = promisify(execCallback);
10
8
 
11
9
  export default class MediaConverter {
@@ -34,33 +32,38 @@ export default class MediaConverter {
34
32
  throw new Error(`Unsupported file type: ${this.mime}`);
35
33
  }
36
34
 
37
- async videoToGif(buffer) {
38
- const tempInput = join(tmpdir(), `input_${Date.now()}.mp4`);
39
- const tempOutput = join(tmpdir(), `output_${Date.now()}.gif`);
35
+ videoToGif = async (data) => {
36
+ const filename = `${tmpdir()}/${Math.random().toString(36).substring(2)}`;
37
+ const videoPath = `${filename}.mp4`;
38
+ const gifPath = `${filename}.gif`;
40
39
 
41
40
  try {
42
- await fs.writeFile(tempInput, buffer);
41
+ // Write the input video buffer to a temporary file
42
+ await fs.writeFile(videoPath, data);
43
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}"`;
44
+ // Execute FFmpeg command to convert video to GIF with lossless option
45
+ const ffmpegCmd = `ffmpeg -i "${videoPath}" -vf "fps=15,scale=320:-1:flags=lanczos" -loop 0 -lossless 0 "${gifPath}"`;
45
46
  await exec(ffmpegCmd);
46
47
 
47
- const gifBuffer = await fs.readFile(tempOutput);
48
+ // Read the resulting GIF as a buffer
49
+ const gifBuffer = await fs.readFile(gifPath);
48
50
 
51
+ // Clean up temporary files
49
52
  await Promise.all([
50
- fs.unlink(tempInput).catch(() => {}),
51
- fs.unlink(tempOutput).catch(() => {}),
53
+ fs.unlink(videoPath).catch(() => {}),
54
+ fs.unlink(gifPath).catch(() => {}),
52
55
  ]);
53
56
 
54
57
  return gifBuffer;
55
58
  } catch (error) {
59
+ // Clean up files in case of an error
56
60
  await Promise.all([
57
- fs.unlink(tempInput).catch(() => {}),
58
- fs.unlink(tempOutput).catch(() => {}),
61
+ fs.unlink(videoPath).catch(() => {}),
62
+ fs.unlink(gifPath).catch(() => {}),
59
63
  ]);
60
- throw new Error(`Failed to convert video to gif: ${error.message}`);
64
+ throw new Error(`Failed to convert video to GIF: ${error.message}`);
61
65
  }
62
- }
63
-
66
+ };
64
67
  async ToWebp(buffer) {
65
68
  const fileType = await fileTypeFromBuffer(buffer);
66
69
  if (!fileType) throw new Error("Invalid file type");