@shibam/sticker-maker 1.0.10 โ†’ 1.1.0

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.
@@ -0,0 +1,48 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Readable } from 'stream';
4
+ import { MetaDataType } from './types/metaInfoType.js';
5
+ import { StickerTypes } from './types/StickerTypes.js';
6
+ declare class Sticker {
7
+ private data;
8
+ metaInfo: Partial<MetaDataType>;
9
+ private buffer;
10
+ private mimeType;
11
+ private extType;
12
+ private utils;
13
+ private outBuffer;
14
+ private activeBuff;
15
+ private activeMeta;
16
+ constructor(data: Buffer | string | Readable, metaInfo?: Partial<MetaDataType>);
17
+ /**
18
+ * Initializes the Sticker instance.
19
+ * - Sets default values for metaInfo.
20
+ * - Reads and analyzes input data to determine MIME type and extension type.
21
+ * - Generates ID and quality metadata if not provided.
22
+ */
23
+ private initialize;
24
+ /**
25
+ * Converts input data to a Buffer containing the converted content.
26
+ * @returns Promise<Buffer> A Promise resolving to the converted content as Buffer.
27
+ */
28
+ toBuffer(): Promise<Buffer>;
29
+ /**
30
+ * Converts input data and writes it to a file at the specified outputPath.
31
+ * @param outputPath The path where the converted file will be saved.
32
+ * @returns Promise<void> A Promise resolving when the file is successfully written.
33
+ */
34
+ toFile(outputPath: string): Promise<void>;
35
+ /**
36
+ * Changes the metadata of the sticker.
37
+ * @param newMetaInfo Partial metadata to update.
38
+ * @returns Promise<Buffer> A Promise resolving to the Buffer with updated metadata.
39
+ */
40
+ changeMetaInfo(): Promise<Buffer>;
41
+ /**
42
+ * Extracts metadata from the provided data.
43
+ * @param data Buffer containing the data to extract metadata from.
44
+ * @returns Promise<Partial<MetaDataType>> A Promise resolving to the extracted metadata.
45
+ */
46
+ extractMetaData(data: Buffer): Promise<Partial<MetaDataType>>;
47
+ }
48
+ export { Sticker, StickerTypes };
package/dist/index.js ADDED
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.StickerTypes = exports.Sticker = void 0;
43
+ var fs_1 = __importDefault(require("fs"));
44
+ var utils_js_1 = __importDefault(require("./lib/utils.js"));
45
+ var ToWebp_js_1 = __importDefault(require("./lib/ToWebp.js"));
46
+ var StickerTypes_js_1 = require("./types/StickerTypes.js");
47
+ Object.defineProperty(exports, "StickerTypes", { enumerable: true, get: function () { return StickerTypes_js_1.StickerTypes; } });
48
+ var changeMetaInfo_js_1 = __importDefault(require("./lib/changeMetaInfo.js"));
49
+ var extractMetaData_js_1 = __importDefault(require("./lib/extractMetaData.js"));
50
+ var Sticker = /** @class */ (function () {
51
+ function Sticker(data, metaInfo) {
52
+ if (metaInfo === void 0) { metaInfo = {}; }
53
+ this.data = data;
54
+ this.metaInfo = metaInfo;
55
+ this.utils = new utils_js_1.default();
56
+ this.buffer = Buffer.from([]);
57
+ this.outBuffer = Buffer.from([]);
58
+ this.activeBuff = false;
59
+ this.activeMeta = false;
60
+ this.mimeType = '';
61
+ this.extType = '';
62
+ }
63
+ /**
64
+ * Initializes the Sticker instance.
65
+ * - Sets default values for metaInfo.
66
+ * - Reads and analyzes input data to determine MIME type and extension type.
67
+ * - Generates ID and quality metadata if not provided.
68
+ */
69
+ Sticker.prototype.initialize = function () {
70
+ return __awaiter(this, void 0, void 0, function () {
71
+ var _a, fileType, error_1;
72
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
73
+ return __generator(this, function (_l) {
74
+ switch (_l.label) {
75
+ case 0:
76
+ _l.trys.push([0, 3, , 4]);
77
+ _a = this;
78
+ return [4 /*yield*/, this.utils.buffer(this.data)];
79
+ case 1:
80
+ _a.buffer = _l.sent();
81
+ return [4 /*yield*/, this.utils.getMimeType(this.buffer)];
82
+ case 2:
83
+ fileType = _l.sent();
84
+ this.mimeType = (_b = fileType === null || fileType === void 0 ? void 0 : fileType.mime) !== null && _b !== void 0 ? _b : '';
85
+ this.extType = (_c = fileType === null || fileType === void 0 ? void 0 : fileType.ext) !== null && _c !== void 0 ? _c : '';
86
+ this.metaInfo.pack = (_d = this.metaInfo.pack) !== null && _d !== void 0 ? _d : '';
87
+ this.metaInfo.author = (_e = this.metaInfo.author) !== null && _e !== void 0 ? _e : '';
88
+ this.metaInfo.id = (_f = this.metaInfo.id) !== null && _f !== void 0 ? _f : this.utils.getId();
89
+ this.metaInfo.category = (_g = this.metaInfo.category) !== null && _g !== void 0 ? _g : [];
90
+ this.metaInfo.type = (_h = this.metaInfo.type) !== null && _h !== void 0 ? _h : StickerTypes_js_1.StickerTypes.DEFAULT;
91
+ this.metaInfo.quality = (_k = (_j = this.metaInfo) === null || _j === void 0 ? void 0 : _j.quality) !== null && _k !== void 0 ? _k : this.utils.getQuality(this.buffer);
92
+ return [3 /*break*/, 4];
93
+ case 3:
94
+ error_1 = _l.sent();
95
+ throw new Error("Initialization error: ".concat(error_1));
96
+ case 4: return [2 /*return*/];
97
+ }
98
+ });
99
+ });
100
+ };
101
+ /**
102
+ * Converts input data to a Buffer containing the converted content.
103
+ * @returns Promise<Buffer> A Promise resolving to the converted content as Buffer.
104
+ */
105
+ Sticker.prototype.toBuffer = function () {
106
+ return __awaiter(this, void 0, void 0, function () {
107
+ var buffer, _a, error_2;
108
+ return __generator(this, function (_b) {
109
+ switch (_b.label) {
110
+ case 0:
111
+ _b.trys.push([0, 4, , 5]);
112
+ return [4 /*yield*/, this.initialize()];
113
+ case 1:
114
+ _b.sent();
115
+ return [4 /*yield*/, (0, ToWebp_js_1.default)(this.buffer, this.metaInfo, this.extType, this.mimeType)];
116
+ case 2:
117
+ buffer = _b.sent();
118
+ _a = this;
119
+ return [4 /*yield*/, new changeMetaInfo_js_1.default(this.metaInfo).add(buffer)];
120
+ case 3:
121
+ _a.outBuffer = _b.sent();
122
+ this.activeBuff = true;
123
+ return [2 /*return*/, this.outBuffer];
124
+ case 4:
125
+ error_2 = _b.sent();
126
+ this.activeBuff = false;
127
+ throw new Error("Conversion to buffer failed: ".concat(error_2));
128
+ case 5: return [2 /*return*/];
129
+ }
130
+ });
131
+ });
132
+ };
133
+ /**
134
+ * Converts input data and writes it to a file at the specified outputPath.
135
+ * @param outputPath The path where the converted file will be saved.
136
+ * @returns Promise<void> A Promise resolving when the file is successfully written.
137
+ */
138
+ Sticker.prototype.toFile = function (outputPath) {
139
+ return __awaiter(this, void 0, void 0, function () {
140
+ var error_3;
141
+ var _a;
142
+ return __generator(this, function (_b) {
143
+ switch (_b.label) {
144
+ case 0:
145
+ _b.trys.push([0, 6, , 7]);
146
+ if (!(!this.activeBuff && !this.activeMeta && ((_a = this.extType) === null || _a === void 0 ? void 0 : _a.includes('webp')))) return [3 /*break*/, 2];
147
+ return [4 /*yield*/, this.changeMetaInfo()];
148
+ case 1:
149
+ _b.sent();
150
+ return [3 /*break*/, 4];
151
+ case 2: return [4 /*yield*/, this.toBuffer()];
152
+ case 3:
153
+ _b.sent();
154
+ _b.label = 4;
155
+ case 4: return [4 /*yield*/, fs_1.default.promises.writeFile(outputPath, this.outBuffer)];
156
+ case 5:
157
+ _b.sent();
158
+ return [3 /*break*/, 7];
159
+ case 6:
160
+ error_3 = _b.sent();
161
+ throw new Error("Conversion to file failed: ".concat(error_3));
162
+ case 7: return [2 /*return*/];
163
+ }
164
+ });
165
+ });
166
+ };
167
+ /**
168
+ * Changes the metadata of the sticker.
169
+ * @param newMetaInfo Partial metadata to update.
170
+ * @returns Promise<Buffer> A Promise resolving to the Buffer with updated metadata.
171
+ */
172
+ Sticker.prototype.changeMetaInfo = function () {
173
+ return __awaiter(this, void 0, void 0, function () {
174
+ var _a, error_4;
175
+ return __generator(this, function (_b) {
176
+ switch (_b.label) {
177
+ case 0:
178
+ _b.trys.push([0, 3, , 4]);
179
+ return [4 /*yield*/, this.initialize()];
180
+ case 1:
181
+ _b.sent();
182
+ _a = this;
183
+ return [4 /*yield*/, new changeMetaInfo_js_1.default(this.metaInfo).add(this.buffer)];
184
+ case 2:
185
+ _a.outBuffer = _b.sent();
186
+ this.activeMeta = true;
187
+ return [2 /*return*/, this.outBuffer];
188
+ case 3:
189
+ error_4 = _b.sent();
190
+ this.activeMeta = false;
191
+ throw new Error("Error changing meta info: ".concat(error_4));
192
+ case 4: return [2 /*return*/];
193
+ }
194
+ });
195
+ });
196
+ };
197
+ /**
198
+ * Extracts metadata from the provided data.
199
+ * @param data Buffer containing the data to extract metadata from.
200
+ * @returns Promise<Partial<MetaDataType>> A Promise resolving to the extracted metadata.
201
+ */
202
+ Sticker.prototype.extractMetaData = function (data) {
203
+ return __awaiter(this, void 0, void 0, function () {
204
+ var error_5;
205
+ return __generator(this, function (_a) {
206
+ switch (_a.label) {
207
+ case 0:
208
+ _a.trys.push([0, 2, , 3]);
209
+ return [4 /*yield*/, this.initialize()];
210
+ case 1:
211
+ _a.sent();
212
+ return [2 /*return*/, (0, extractMetaData_js_1.default)(data)];
213
+ case 2:
214
+ error_5 = _a.sent();
215
+ throw new Error("Error extracting meta data: ".concat(error_5));
216
+ case 3: return [2 /*return*/];
217
+ }
218
+ });
219
+ });
220
+ };
221
+ return Sticker;
222
+ }());
223
+ exports.Sticker = Sticker;
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { MetaDataType } from '../types/metaInfoType.js';
3
+ /**
4
+ * Converts a given buffer to WebP format with optional transformations.
5
+ *
6
+ * @param {Buffer} buffer - The input buffer to be converted.
7
+ * @param {Partial<MetaDataType>} metaInfo - Metadata information for the conversion.
8
+ * @param {string} mimeExt - The MIME extension of the input buffer.
9
+ * @param {string} mimeType - The MIME type of the input buffer.
10
+ * @returns {Promise<Buffer>} - A promise that resolves to the converted WebP buffer.
11
+ */
12
+ declare const ToWebp: (buffer: Buffer, metaInfo: Partial<MetaDataType>, mimeExt: string, mimeType: string) => Promise<Buffer>;
13
+ export default ToWebp;
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ var sharp_1 = __importStar(require("sharp"));
66
+ var StickerTypes_js_1 = require("../types/StickerTypes.js");
67
+ var toGif_js_1 = __importDefault(require("./toGif.js"));
68
+ /**
69
+ * Converts a given buffer to WebP format with optional transformations.
70
+ *
71
+ * @param {Buffer} buffer - The input buffer to be converted.
72
+ * @param {Partial<MetaDataType>} metaInfo - Metadata information for the conversion.
73
+ * @param {string} mimeExt - The MIME extension of the input buffer.
74
+ * @param {string} mimeType - The MIME type of the input buffer.
75
+ * @returns {Promise<Buffer>} - A promise that resolves to the converted WebP buffer.
76
+ */
77
+ var ToWebp = function (buffer, metaInfo, mimeExt, mimeType) { return __awaiter(void 0, void 0, void 0, function () {
78
+ var data, _a, isAnimated, res, error_1;
79
+ return __generator(this, function (_b) {
80
+ switch (_b.label) {
81
+ case 0:
82
+ _b.trys.push([0, 4, , 5]);
83
+ if (mimeExt === 'webp' || mimeExt === 'webm')
84
+ return [2 /*return*/, buffer];
85
+ if (!(mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('video'))) return [3 /*break*/, 2];
86
+ return [4 /*yield*/, (0, toGif_js_1.default)(buffer, mimeExt, metaInfo.type || StickerTypes_js_1.StickerTypes.DEFAULT)];
87
+ case 1:
88
+ _a = _b.sent();
89
+ return [3 /*break*/, 3];
90
+ case 2:
91
+ _a = buffer;
92
+ _b.label = 3;
93
+ case 3:
94
+ data = _a;
95
+ isAnimated = (mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('video')) || (mimeExt === null || mimeExt === void 0 ? void 0 : mimeExt.includes('gif'));
96
+ res = (0, sharp_1.default)(data, { animated: isAnimated });
97
+ if (metaInfo.type === StickerTypes_js_1.StickerTypes.CIRCLE) {
98
+ res.resize(512, 512, {
99
+ fit: sharp_1.fit.cover
100
+ }).composite([
101
+ {
102
+ input: Buffer.from("<svg width=\"512\" height=\"512\"><circle cx=\"256\" cy=\"256\" r=\"256\" fill=\"\"/></svg>"),
103
+ blend: 'dest-in',
104
+ gravity: 'northeast',
105
+ tile: true
106
+ }
107
+ ]);
108
+ }
109
+ else if (metaInfo.type === StickerTypes_js_1.StickerTypes.SQUARE && !(mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('video'))) {
110
+ res.resize(512, 512, {
111
+ fit: sharp_1.fit.fill
112
+ });
113
+ }
114
+ return [2 /*return*/, res
115
+ .toFormat('webp')
116
+ .webp({
117
+ quality: metaInfo.quality,
118
+ lossless: true
119
+ })
120
+ .toBuffer()];
121
+ case 4:
122
+ error_1 = _b.sent();
123
+ throw new Error("Conversion failed: ".concat(error_1));
124
+ case 5: return [2 /*return*/];
125
+ }
126
+ });
127
+ }); };
128
+ exports.default = ToWebp;
@@ -0,0 +1,33 @@
1
+ /// <reference path="../../src/lib/node-webpmux.d.ts" />
2
+ /// <reference types="node" />
3
+ import Image from 'node-webpmux';
4
+ /**
5
+ * The Exif class is responsible for handling the metadata (Exif data)
6
+ * for sticker images, particularly those used in messaging applications.
7
+ */
8
+ export default class Exif {
9
+ private data;
10
+ private exif;
11
+ /**
12
+ * Constructs an Exif instance with the given options.
13
+ * @param options - An object containing metadata for the sticker.
14
+ */
15
+ constructor(options: any);
16
+ /**
17
+ * Builds the Exif metadata as a Buffer.
18
+ * @returns A Buffer containing the constructed Exif data.
19
+ */
20
+ build: () => Buffer;
21
+ /**
22
+ * Adds the Exif metadata to the given image.
23
+ * @param image - A Buffer or Image instance representing the image to which Exif data should be added.
24
+ * @returns A Promise that resolves to a Buffer containing the image with the added Exif data.
25
+ */
26
+ add: (image: Buffer | Image.Image) => Promise<Buffer>;
27
+ /**
28
+ * Loads the image from a Buffer or string and returns an Image instance.
29
+ * @param image - A Buffer or string representing the image to be loaded.
30
+ * @returns A Promise that resolves to an Image instance.
31
+ */
32
+ load: (image: Buffer | string) => Promise<Image.Image>;
33
+ }
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var node_webpmux_1 = __importDefault(require("node-webpmux"));
43
+ var util_1 = require("util");
44
+ /**
45
+ * The Exif class is responsible for handling the metadata (Exif data)
46
+ * for sticker images, particularly those used in messaging applications.
47
+ */
48
+ var Exif = /** @class */ (function () {
49
+ /**
50
+ * Constructs an Exif instance with the given options.
51
+ * @param options - An object containing metadata for the sticker.
52
+ */
53
+ function Exif(options) {
54
+ var _this = this;
55
+ this.data = {};
56
+ this.exif = null;
57
+ /**
58
+ * Builds the Exif metadata as a Buffer.
59
+ * @returns A Buffer containing the constructed Exif data.
60
+ */
61
+ this.build = function () {
62
+ var data = JSON.stringify(_this.data);
63
+ var exif = Buffer.concat([
64
+ Buffer.from([
65
+ 0x49, 0x49, 0x2a, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00,
66
+ 0x00, 0x16, 0x00, 0x00, 0x00
67
+ ]),
68
+ Buffer.from(data, 'utf-8')
69
+ ]);
70
+ exif.writeUIntLE(new util_1.TextEncoder().encode(data).length, 14, 4);
71
+ return exif;
72
+ };
73
+ /**
74
+ * Adds the Exif metadata to the given image.
75
+ * @param image - A Buffer or Image instance representing the image to which Exif data should be added.
76
+ * @returns A Promise that resolves to a Buffer containing the image with the added Exif data.
77
+ */
78
+ this.add = function (image) { return __awaiter(_this, void 0, void 0, function () {
79
+ var exif, _a;
80
+ return __generator(this, function (_b) {
81
+ switch (_b.label) {
82
+ case 0:
83
+ exif = this.exif || this.build();
84
+ if (!(image instanceof node_webpmux_1.default.Image)) return [3 /*break*/, 1];
85
+ _a = image;
86
+ return [3 /*break*/, 3];
87
+ case 1: return [4 /*yield*/, this.load(image)
88
+ // Set the Exif data on the image and save it.
89
+ ];
90
+ case 2:
91
+ _a = _b.sent();
92
+ _b.label = 3;
93
+ case 3:
94
+ // Load the image if it is not already an instance of Image.Image.
95
+ image = _a;
96
+ // Set the Exif data on the image and save it.
97
+ image.exif = exif;
98
+ return [4 /*yield*/, image.save(null)];
99
+ case 4: return [2 /*return*/, _b.sent()];
100
+ }
101
+ });
102
+ }); };
103
+ /**
104
+ * Loads the image from a Buffer or string and returns an Image instance.
105
+ * @param image - A Buffer or string representing the image to be loaded.
106
+ * @returns A Promise that resolves to an Image instance.
107
+ */
108
+ this.load = function (image) { return __awaiter(_this, void 0, void 0, function () {
109
+ var img;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ img = new node_webpmux_1.default.Image();
114
+ return [4 /*yield*/, img.load(image)];
115
+ case 1:
116
+ _a.sent();
117
+ return [2 /*return*/, img];
118
+ }
119
+ });
120
+ }); };
121
+ this.data['sticker-pack-id'] = options.id || '';
122
+ this.data['sticker-pack-name'] = options.pack || '';
123
+ this.data['sticker-pack-publisher'] = options.author || '';
124
+ this.data['emojis'] = options.category || ['๐Ÿ˜น'];
125
+ }
126
+ return Exif;
127
+ }());
128
+ exports.default = Exif;
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Extracts metadata from a WebP image.
4
+ * @param {Buffer}image - The image buffer to extract metadata from
5
+ */
6
+ declare const extractMetadata: (image: Buffer) => Promise<any>;
7
+ export default extractMetadata;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var node_webpmux_1 = __importDefault(require("node-webpmux"));
43
+ /**
44
+ * Extracts metadata from a WebP image.
45
+ * @param {Buffer}image - The image buffer to extract metadata from
46
+ */
47
+ var extractMetadata = function (image) { return __awaiter(void 0, void 0, void 0, function () {
48
+ var img, exif;
49
+ var _a, _b, _c;
50
+ return __generator(this, function (_d) {
51
+ switch (_d.label) {
52
+ case 0:
53
+ img = new node_webpmux_1.default.Image();
54
+ return [4 /*yield*/, img.load(image)];
55
+ case 1:
56
+ _d.sent();
57
+ exif = (_b = (_a = img.exif) === null || _a === void 0 ? void 0 : _a.toString('utf-8')) !== null && _b !== void 0 ? _b : '{}';
58
+ return [2 /*return*/, JSON.parse((_c = exif.substring(exif.indexOf('{'), exif.lastIndexOf('}') + 1)) !== null && _c !== void 0 ? _c : '{}')];
59
+ }
60
+ });
61
+ }); };
62
+ exports.default = extractMetadata;
@@ -0,0 +1,4 @@
1
+ /// <reference types="node" />
2
+ import { StickerTypes } from '../types/StickerTypes.js';
3
+ declare const videoToGif: (buffer: Buffer, extType: string, type: StickerTypes) => Promise<Buffer>;
4
+ export default videoToGif;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
43
+ var ffmpeg_1 = __importDefault(require("@ffmpeg-installer/ffmpeg"));
44
+ var stream_1 = require("stream");
45
+ var StickerTypes_js_1 = require("../types/StickerTypes.js");
46
+ fluent_ffmpeg_1.default.setFfmpegPath(ffmpeg_1.default.path);
47
+ var videoToGif = function (buffer, extType, type) {
48
+ return new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
49
+ var outputStream, inputStream, chunks_1, shape;
50
+ return __generator(this, function (_a) {
51
+ try {
52
+ outputStream = new stream_1.PassThrough();
53
+ inputStream = new stream_1.PassThrough();
54
+ inputStream.end(buffer);
55
+ chunks_1 = [];
56
+ outputStream.on('data', function (chunk) {
57
+ chunks_1.push(chunk);
58
+ });
59
+ outputStream.on('end', function () { return __awaiter(void 0, void 0, void 0, function () {
60
+ return __generator(this, function (_a) {
61
+ resolve(Buffer.concat(chunks_1));
62
+ return [2 /*return*/];
63
+ });
64
+ }); });
65
+ outputStream.on('error', function (err) { return __awaiter(void 0, void 0, void 0, function () {
66
+ return __generator(this, function (_a) {
67
+ switch (_a.label) {
68
+ case 0: return [4 /*yield*/, videoToGif(buffer, extType, type)];
69
+ case 1:
70
+ _a.sent();
71
+ reject(err);
72
+ return [2 /*return*/];
73
+ }
74
+ });
75
+ }); });
76
+ shape = type === StickerTypes_js_1.StickerTypes.SQUARE
77
+ ? 'scale=320:-1:flags=lanczos,fps=10,crop=min(iw\\,ih):min(iw\\,ih)'
78
+ : 'scale=320:-1:flags=lanczos,fps=10';
79
+ (0, fluent_ffmpeg_1.default)(inputStream)
80
+ .inputFormat(extType)
81
+ .outputOptions(['-vf', shape, '-loop', '0', '-lossless', '0', '-t', '6', '-preset', 'ultrafast'])
82
+ .toFormat('gif')
83
+ .pipe(outputStream, { end: true });
84
+ }
85
+ catch (error) {
86
+ reject(error);
87
+ }
88
+ return [2 /*return*/];
89
+ });
90
+ }); });
91
+ };
92
+ exports.default = videoToGif;
@@ -0,0 +1,39 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Readable } from 'stream';
4
+ export default class Utils {
5
+ constructor();
6
+ /**
7
+ * Converts various types of input data to a Buffer.
8
+ * @param data Input data as Buffer, string (file path), or Readable stream.
9
+ * @returns Promise<Buffer> A Promise resolving to the converted Buffer.
10
+ * @throws Error if conversion fails.
11
+ */
12
+ buffer(data: Buffer | string | Readable): Promise<Buffer>;
13
+ /**
14
+ * Converts a Readable stream to a Buffer.
15
+ * @param stream Readable stream to convert.
16
+ * @returns Promise<Buffer> A Promise resolving to the converted Buffer.
17
+ */
18
+ streamToBuffer(stream: Readable): Promise<Buffer>;
19
+ /**
20
+ * Determines the quality of the data based on its size.
21
+ * @param data Buffer containing the data.
22
+ * @returns number Quality value based on data size.
23
+ */
24
+ getQuality(data: Buffer): number;
25
+ /**
26
+ * Determines the MIME type of the data buffer.
27
+ * @param data Buffer containing the data.
28
+ * @returns Promise<{ mime: string; ext: string }> A Promise resolving to an object with MIME type and extension.
29
+ */
30
+ getMimeType(data: Buffer): Promise<{
31
+ mime: string;
32
+ ext: string;
33
+ } | undefined>;
34
+ /**
35
+ * Generates a random ID.
36
+ * @returns string A random alphanumeric ID.
37
+ */
38
+ getId(): string;
39
+ }
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
46
+ };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
50
+ Object.defineProperty(exports, "__esModule", { value: true });
51
+ var stream_1 = require("stream");
52
+ var fs_1 = __importDefault(require("fs"));
53
+ var file_type_1 = require("file-type");
54
+ var Utils = /** @class */ (function () {
55
+ function Utils() {
56
+ }
57
+ /**
58
+ * Converts various types of input data to a Buffer.
59
+ * @param data Input data as Buffer, string (file path), or Readable stream.
60
+ * @returns Promise<Buffer> A Promise resolving to the converted Buffer.
61
+ * @throws Error if conversion fails.
62
+ */
63
+ Utils.prototype.buffer = function (data) {
64
+ return __awaiter(this, void 0, void 0, function () {
65
+ var buffer, _a, _b, error_1;
66
+ return __generator(this, function (_c) {
67
+ switch (_c.label) {
68
+ case 0:
69
+ _c.trys.push([0, 7, , 8]);
70
+ if (!(typeof data === 'string')) return [3 /*break*/, 2];
71
+ return [4 /*yield*/, fs_1.default.promises.readFile(data)];
72
+ case 1:
73
+ _a = _c.sent();
74
+ return [3 /*break*/, 6];
75
+ case 2:
76
+ if (!(data instanceof stream_1.Readable)) return [3 /*break*/, 4];
77
+ return [4 /*yield*/, this.streamToBuffer(data)];
78
+ case 3:
79
+ _b = _c.sent();
80
+ return [3 /*break*/, 5];
81
+ case 4:
82
+ _b = Buffer.from(data);
83
+ _c.label = 5;
84
+ case 5:
85
+ _a = _b;
86
+ _c.label = 6;
87
+ case 6:
88
+ buffer = _a;
89
+ return [2 /*return*/, buffer];
90
+ case 7:
91
+ error_1 = _c.sent();
92
+ throw new Error("Error converting to buffer: ".concat(error_1));
93
+ case 8: return [2 /*return*/];
94
+ }
95
+ });
96
+ });
97
+ };
98
+ /**
99
+ * Converts a Readable stream to a Buffer.
100
+ * @param stream Readable stream to convert.
101
+ * @returns Promise<Buffer> A Promise resolving to the converted Buffer.
102
+ */
103
+ Utils.prototype.streamToBuffer = function (stream) {
104
+ return __awaiter(this, void 0, void 0, function () {
105
+ var chunks;
106
+ return __generator(this, function (_a) {
107
+ chunks = [];
108
+ return [2 /*return*/, new Promise(function (resolve, reject) {
109
+ stream.on('data', function (chunk) {
110
+ if (Buffer.isBuffer(chunk)) {
111
+ chunks.push(chunk);
112
+ }
113
+ else {
114
+ chunks.push(Buffer.from(chunk));
115
+ }
116
+ });
117
+ stream.on('end', function () {
118
+ resolve(Buffer.concat(chunks));
119
+ });
120
+ stream.on('error', function (err) {
121
+ reject(err);
122
+ });
123
+ })];
124
+ });
125
+ });
126
+ };
127
+ /**
128
+ * Determines the quality of the data based on its size.
129
+ * @param data Buffer containing the data.
130
+ * @returns number Quality value based on data size.
131
+ */
132
+ Utils.prototype.getQuality = function (data) {
133
+ var buffer = Buffer.from(data);
134
+ var bytes = buffer.length / 1024;
135
+ var quality = bytes > 4 * 1024 ? 8 : bytes > 3 * 1024 ? 10 : bytes > 2 * 1024 ? 12 : 15;
136
+ return quality;
137
+ };
138
+ /**
139
+ * Determines the MIME type of the data buffer.
140
+ * @param data Buffer containing the data.
141
+ * @returns Promise<{ mime: string; ext: string }> A Promise resolving to an object with MIME type and extension.
142
+ */
143
+ Utils.prototype.getMimeType = function (data) {
144
+ return __awaiter(this, void 0, void 0, function () {
145
+ var fileType, error_2;
146
+ return __generator(this, function (_a) {
147
+ switch (_a.label) {
148
+ case 0:
149
+ _a.trys.push([0, 2, , 3]);
150
+ return [4 /*yield*/, (0, file_type_1.fromBuffer)(data)];
151
+ case 1:
152
+ fileType = _a.sent();
153
+ return [2 /*return*/, fileType];
154
+ case 2:
155
+ error_2 = _a.sent();
156
+ console.error("Error getting MIME type: ".concat(error_2));
157
+ return [2 /*return*/, undefined];
158
+ case 3: return [2 /*return*/];
159
+ }
160
+ });
161
+ });
162
+ };
163
+ /**
164
+ * Generates a random ID.
165
+ * @returns string A random alphanumeric ID.
166
+ */
167
+ Utils.prototype.getId = function () {
168
+ return __spreadArray([], Array(5), true).map(function () { return Math.random().toString(36).substring(2, 15); }).join('');
169
+ };
170
+ return Utils;
171
+ }());
172
+ exports.default = Utils;
@@ -0,0 +1,5 @@
1
+ export declare enum StickerTypes {
2
+ DEFAULT = 0,
3
+ SQUARE = 1,
4
+ CIRCLE = 2
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StickerTypes = void 0;
4
+ var StickerTypes;
5
+ (function (StickerTypes) {
6
+ StickerTypes[StickerTypes["DEFAULT"] = 0] = "DEFAULT";
7
+ StickerTypes[StickerTypes["SQUARE"] = 1] = "SQUARE";
8
+ StickerTypes[StickerTypes["CIRCLE"] = 2] = "CIRCLE";
9
+ })(StickerTypes || (exports.StickerTypes = StickerTypes = {}));
@@ -0,0 +1,8 @@
1
+ type LoveEmojis = 'โค' | '๐Ÿ˜' | '๐Ÿ˜˜' | '๐Ÿ’•' | '๐Ÿ˜ป' | '๐Ÿ’‘' | '๐Ÿ‘ฉโ€โคโ€๐Ÿ‘ฉ' | '๐Ÿ‘จโ€โคโ€๐Ÿ‘จ' | '๐Ÿ’' | '๐Ÿ‘ฉโ€โคโ€๐Ÿ’‹โ€๐Ÿ‘ฉ' | '๐Ÿ‘จโ€โคโ€๐Ÿ’‹โ€๐Ÿ‘จ' | '๐Ÿงก' | '๐Ÿ’›' | '๐Ÿ’š' | '๐Ÿ’™' | '๐Ÿ’œ' | '๐Ÿ–ค' | '๐Ÿ’”' | 'โฃ' | '๐Ÿ’ž' | '๐Ÿ’“' | '๐Ÿ’—' | '๐Ÿ’–' | '๐Ÿ’˜' | '๐Ÿ’' | '๐Ÿ’Ÿ' | 'โ™ฅ' | '๐Ÿ’Œ' | '๐Ÿ’‹' | '๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿ‘ฉ' | '๐Ÿ‘จโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿ‘จ' | '๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ‘จ' | '๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ‘ฉ' | '๐Ÿ‘จโ€โค๏ธโ€๐Ÿ‘จ' | '๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿ‘จ' | '๐Ÿ‘ฌ' | '๐Ÿ‘ญ' | '๐Ÿ‘ซ' | '๐Ÿฅฐ' | '๐Ÿ˜š' | '๐Ÿ˜™' | '๐Ÿ‘„' | '๐ŸŒน' | '๐Ÿ˜ฝ' | 'โฃ๏ธ' | 'โค๏ธ';
2
+ type HappyEmojis = '๐Ÿ˜€' | '๐Ÿ˜ƒ' | '๐Ÿ˜„' | '๐Ÿ˜' | '๐Ÿ˜†' | '๐Ÿ˜…' | '๐Ÿ˜‚' | '๐Ÿคฃ' | '๐Ÿ™‚' | '๐Ÿ˜›' | '๐Ÿ˜' | '๐Ÿ˜œ' | '๐Ÿคช' | '๐Ÿค—' | '๐Ÿ˜บ' | '๐Ÿ˜ธ' | '๐Ÿ˜น' | 'โ˜บ' | '๐Ÿ˜Œ' | '๐Ÿ˜‰' | '๐Ÿค—' | '๐Ÿ˜Š';
3
+ type SadEmojis = 'โ˜น' | '๐Ÿ˜ฃ' | '๐Ÿ˜–' | '๐Ÿ˜ซ' | '๐Ÿ˜ฉ' | '๐Ÿ˜ข' | '๐Ÿ˜ญ' | '๐Ÿ˜ž' | '๐Ÿ˜”' | '๐Ÿ˜Ÿ' | '๐Ÿ˜•' | '๐Ÿ˜ค' | '๐Ÿ˜ ' | '๐Ÿ˜ฅ' | '๐Ÿ˜ฐ' | '๐Ÿ˜จ' | '๐Ÿ˜ฟ' | '๐Ÿ˜พ' | '๐Ÿ˜“' | '๐Ÿ™โ€โ™‚๏ธ' | '๐Ÿ™โ€โ™€๏ธ' | '๐Ÿ’”' | '๐Ÿ™' | '๐Ÿฅบ' | '๐Ÿค•' | 'โ˜”๏ธ' | 'โ›ˆ' | '๐ŸŒฉ' | '๐ŸŒง';
4
+ type AngryEmojis = '๐Ÿ˜ฏ' | '๐Ÿ˜ฆ' | '๐Ÿ˜ง' | '๐Ÿ˜ฎ' | '๐Ÿ˜ฒ' | '๐Ÿ™€' | '๐Ÿ˜ฑ' | '๐Ÿคฏ' | '๐Ÿ˜ณ' | 'โ—' | 'โ•' | '๐Ÿคฌ' | '๐Ÿ˜ก' | '๐Ÿ˜ ' | '๐Ÿ™„' | '๐Ÿ‘ฟ' | '๐Ÿ˜พ' | '๐Ÿ˜ค' | '๐Ÿ’ข' | '๐Ÿ‘บ' | '๐Ÿ—ฏ๏ธ' | '๐Ÿ˜’' | '๐Ÿฅต';
5
+ type GreetEmojis = '๐Ÿ‘‹';
6
+ type CelebrateEmojis = '๐ŸŽŠ' | '๐ŸŽ‰' | '๐ŸŽ' | '๐ŸŽˆ' | '๐Ÿ‘ฏโ€โ™‚๏ธ' | '๐Ÿ‘ฏ' | '๐Ÿ‘ฏโ€โ™€๏ธ' | '๐Ÿ’ƒ' | '๐Ÿ•บ' | '๐Ÿ”ฅ' | 'โญ๏ธ' | 'โœจ' | '๐Ÿ’ซ' | '๐ŸŽ‡' | '๐ŸŽ†' | '๐Ÿป' | '๐Ÿฅ‚' | '๐Ÿพ' | '๐ŸŽ‚' | '๐Ÿฐ';
7
+ export type category = LoveEmojis | HappyEmojis | SadEmojis | AngryEmojis | GreetEmojis | CelebrateEmojis;
8
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import { category } from './categoryType.js';
2
+ import { StickerTypes } from './StickerTypes.js';
3
+ export interface MetaDataType {
4
+ pack?: string;
5
+ author?: string;
6
+ id?: string;
7
+ category?: category[];
8
+ type?: StickerTypes;
9
+ quality?: number;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shibam/sticker-maker",
3
- "version": "1.0.10",
3
+ "version": "1.1.0",
4
4
  "description": "A package for creating stickers",
5
5
  "main": "dist/index.js",
6
6
  "type": "commonjs",
@@ -33,8 +33,12 @@
33
33
  "typescript"
34
34
  ],
35
35
  "dependencies": {
36
+ "@ffmpeg-installer/ffmpeg": "^1.1.0",
37
+ "@types/fluent-ffmpeg": "^2.1.24",
36
38
  "file-type": "16.5.0",
37
- "node-webpmux": "^3.2.0"
39
+ "fluent-ffmpeg": "^2.1.3",
40
+ "node-webpmux": "^3.2.0",
41
+ "sharp": "^0.33.4"
38
42
  },
39
43
  "devDependencies": {
40
44
  "@types/node": "^20.10.0",
package/readme.md CHANGED
@@ -1,13 +1,12 @@
1
1
  # @shibam/sticker-maker
2
2
 
3
- `@shibam/sticker-maker` is a lightweight utility library designed for converting images and videos into stickers while allowing customization of metadata. It supports various input types and ensures high-quality sticker conversion. This module has minimal dependencies, ensuring efficient performance. If you encounter any issues, please feel free to open an issue. However, please check if a similar issue has already been reported before creating a new one. Happy Coding (โ โ‰งโ โ–ฝโ โ‰ฆโ ).
3
+ `@shibam/sticker-maker` is a lightweight utility library designed for converting images and videos into stickers while allowing customization of metadata. you don't have to download ffmpeg in terminal. It supports various input types and ensures high-quality sticker conversion. This module has minimal dependencies, ensuring efficient performance. If you encounter any issues, please feel free to open an issue. However, please check if a similar issue has already been reported before creating a new one. Happy Coding (โ โ‰งโ โ–ฝโ โ‰ฆโ ).
4
4
 
5
5
  # Sticker Class
6
6
 
7
7
  The `Sticker` class is a utility for converting images and videos into sticker format, with options for metadata customization and manipulation.
8
8
 
9
9
  ## Installation
10
- # โš ๏ธ Before installing this make sure you have downloaded ffmpeg
11
10
 
12
11
  You can install the package using npm:
13
12
 
@@ -31,7 +30,6 @@ const sticker = new Sticker("path/to/image.png", {
31
30
  category: ['๐Ÿ˜‚','๐Ÿ˜น'],
32
31
  type: StickerTypes.DEFAULT,
33
32
  quality: 30,
34
- background: "red"
35
33
  });
36
34
 
37
35
  try {
@@ -49,7 +47,6 @@ const sticker2 = new Sticker("path/to/another/image.png", {
49
47
  category: ['๐Ÿ˜Š','๐Ÿ‘'],
50
48
  type: StickerTypes.CIRCLE,
51
49
  quality: 50,
52
- background: "blue"
53
50
  });
54
51
 
55
52
  try {
@@ -100,7 +97,6 @@ enum StickerTypes {
100
97
  DEFAULT,
101
98
  CIRCLE,
102
99
  SQUARE,
103
- FIT
104
100
  }
105
101
  ```
106
102
 
@@ -110,7 +106,7 @@ This package is licensed under the MIT License.
110
106
 
111
107
  ## Contributing
112
108
 
113
- Contributions are welcome. Feel free to open issues or submit pull requests on [GitHub](https://github.com/your/repository).
109
+ Contributions are welcome. Feel free to open issues or submit pull requests on [GitHub](https://github.com/NekoSenpai69/Sticker-Maker).
114
110
 
115
111
  ---
116
112