@shibam/sticker-maker 1.0.7 → 1.0.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/dist/index.js CHANGED
@@ -114,25 +114,25 @@ var Sticker = /** @class */ (function () {
114
114
  */
115
115
  Sticker.prototype.toBuffer = function () {
116
116
  return __awaiter(this, void 0, void 0, function () {
117
- var buffer, _a, error_2;
118
- return __generator(this, function (_b) {
119
- switch (_b.label) {
117
+ var buffer, MetaBuff, error_2;
118
+ return __generator(this, function (_a) {
119
+ switch (_a.label) {
120
120
  case 0:
121
- _b.trys.push([0, 4, , 5]);
121
+ _a.trys.push([0, 4, , 5]);
122
122
  return [4 /*yield*/, this.initialize()];
123
123
  case 1:
124
- _b.sent();
124
+ _a.sent();
125
125
  return [4 /*yield*/, (0, ToWebp_js_1.default)(this.buffer, this.metaInfo, this.extType, this.mimeType)];
126
126
  case 2:
127
- buffer = _b.sent();
128
- _a = this;
127
+ buffer = _a.sent();
129
128
  return [4 /*yield*/, new changeMetaInfo_js_1.default(this.metaInfo).add(buffer)];
130
129
  case 3:
131
- _a.outBuffer = _b.sent();
130
+ MetaBuff = _a.sent();
132
131
  this.activeBuff = true;
132
+ this.outBuffer = this.extType !== 'gif' ? MetaBuff : buffer;
133
133
  return [2 /*return*/, this.outBuffer];
134
134
  case 4:
135
- error_2 = _b.sent();
135
+ error_2 = _a.sent();
136
136
  this.activeBuff = false;
137
137
  throw new Error("Conversion to buffer failed: ".concat(error_2));
138
138
  case 5: return [2 /*return*/];
@@ -72,7 +72,7 @@ var ToWebp = function (buffer, metaInfo, mimeExt, mimeType) { return __awaiter(v
72
72
  case 2:
73
73
  // Write input buffer to temporary file
74
74
  _d.sent();
75
- if (!(mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('video'))) return [3 /*break*/, 4];
75
+ if (!((mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('video')) || (mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('webp')))) return [3 /*break*/, 4];
76
76
  return [4 /*yield*/, (0, toGif_js_1.default)(inputPath)];
77
77
  case 3:
78
78
  _a = _d.sent();
@@ -96,7 +96,7 @@ var ToWebp = function (buffer, metaInfo, mimeExt, mimeType) { return __awaiter(v
96
96
  ? "-filter_complex \"color=".concat(metaInfo.background, " [c]; [c][0]scale2ref[cs][0s];[cs][0s]overlay=shortest=1, unsharp=3:3:0.5").concat(metaInfo.type === StickerTypes_js_1.StickerTypes.CIRCLE ||
97
97
  metaInfo.type === StickerTypes_js_1.StickerTypes.SQUARE ||
98
98
  metaInfo.type === StickerTypes_js_1.StickerTypes.FIT
99
- ? ", ".concat(metaInfo.type.replace(/-vf/g, '').replace(/"/g, '').replace('-filter_complex', '').trim())
99
+ ? ", ".concat(metaInfo.type.replaceAll(/-vf/g, '').replaceAll(/"/g, '').replace('-filter_complex', '').trim())
100
100
  : '', "\"")
101
101
  : '-pix_fmt yuva420p',
102
102
  (mimeExt === null || mimeExt === void 0 ? void 0 : mimeExt.includes('gif')) || (mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('video'))
@@ -106,10 +106,7 @@ var ToWebp = function (buffer, metaInfo, mimeExt, mimeType) { return __awaiter(v
106
106
  '-lag-in-frames 0',
107
107
  '-preset default',
108
108
  '-t 10',
109
- '-r 15',
110
109
  '-loop 0',
111
- '-metadata:s:v:0 alpha_mode="1"',
112
- mimeExt === 'gif' ? '-lossless 1' : '-lossless 0'
113
110
  ].join(' ')
114
111
  : '-c:v libwebp',
115
112
  '-q:v',
@@ -117,11 +114,13 @@ var ToWebp = function (buffer, metaInfo, mimeExt, mimeType) { return __awaiter(v
117
114
  '-y',
118
115
  outputPath
119
116
  ];
117
+ //console.log(args.join(" "))
120
118
  // Execute ffmpeg command with constructed arguments
121
119
  return [4 /*yield*/, execAsync("ffmpeg ".concat(args.join(' ')))
122
120
  // Read converted WebP file back into a buffer
123
121
  ];
124
122
  case 6:
123
+ //console.log(args.join(" "))
125
124
  // Execute ffmpeg command with constructed arguments
126
125
  _d.sent();
127
126
  return [4 /*yield*/, (0, promises_1.readFile)(outputPath)];
@@ -51,7 +51,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
53
  var node_webpmux_1 = __importDefault(require("node-webpmux"));
54
- var util_1 = require("util");
55
54
  /**
56
55
  * The Exif class is responsible for handling the metadata (Exif data)
57
56
  * for sticker images, particularly those used in messaging applications.
@@ -71,16 +70,21 @@ var Exif = /** @class */ (function () {
71
70
  */
72
71
  this.build = function () {
73
72
  var data = JSON.stringify(_this.data);
74
- // Construct the Exif header and data sections.
75
- var exif = Buffer.concat([
76
- Buffer.from([
77
- 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00,
78
- 0x00, 0x16, 0x00, 0x00, 0x00
79
- ]),
80
- Buffer.from(data, 'utf-8')
81
- ]);
73
+ var dataBuffer = Buffer.from(data, 'utf-8');
74
+ // Construct the Exif header.
75
+ var exifHeader = Buffer.alloc(22); // Allocate a new buffer of the correct size
76
+ exifHeader.write('Exif\0\0', 0); // Exif header
77
+ exifHeader.writeUInt16LE(0x4949, 6); // II for little-endian
78
+ exifHeader.writeUInt16LE(0x002a, 8); // TIFF header
79
+ exifHeader.writeUInt32LE(0x00000008, 10); // Offset to first IFD
80
+ // Write the APP1 marker and size
81
+ var app1Marker = Buffer.from([0xff, 0xe1]);
82
+ var app1Size = Buffer.alloc(2);
83
+ app1Size.writeUInt16BE(2 + exifHeader.length + dataBuffer.length);
82
84
  // Write the length of the data into the Exif header.
83
- exif.writeUIntLE(new util_1.TextEncoder().encode(data).length, 14, 4);
85
+ exifHeader.writeUInt32LE(dataBuffer.length, 14);
86
+ // Concatenate all parts
87
+ var exif = Buffer.concat([app1Marker, app1Size, exifHeader, dataBuffer]);
84
88
  return exif;
85
89
  };
86
90
  /**
@@ -90,6 +94,7 @@ var Exif = /** @class */ (function () {
90
94
  */
91
95
  this.add = function (image) { return __awaiter(_this, void 0, void 0, function () {
92
96
  var exif, _a;
97
+ var _this = this;
93
98
  return __generator(this, function (_b) {
94
99
  switch (_b.label) {
95
100
  case 0:
@@ -97,7 +102,19 @@ var Exif = /** @class */ (function () {
97
102
  if (!(image instanceof node_webpmux_1.default.Image)) return [3 /*break*/, 1];
98
103
  _a = image;
99
104
  return [3 /*break*/, 3];
100
- case 1: return [4 /*yield*/, this.load(image)
105
+ case 1: return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () {
106
+ var img;
107
+ return __generator(this, function (_a) {
108
+ switch (_a.label) {
109
+ case 0:
110
+ img = new node_webpmux_1.default.Image();
111
+ return [4 /*yield*/, img.load(image)];
112
+ case 1:
113
+ _a.sent();
114
+ return [2 /*return*/, img];
115
+ }
116
+ });
117
+ }); })()
101
118
  // Set the Exif data on the image and save it.
102
119
  ];
103
120
  case 2:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shibam/sticker-maker",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "A package for creating stickers",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
@@ -34,12 +34,11 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "file-type": "16.5.0",
37
- "node-webpmux": "^3.2.0",
38
- "prettier": "^3.3.2"
37
+ "node-webpmux": "^3.2.0"
39
38
  },
40
39
  "devDependencies": {
41
40
  "@types/node": "^20.10.0",
42
41
  "tsx": "^4.7.1",
43
42
  "typescript": "^5.4.5"
44
43
  }
45
- }
44
+ }