@shibam/sticker-maker 1.0.11 → 1.1.1
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 +26 -25
- package/dist/lib/ToWebp.d.ts +8 -8
- package/dist/lib/ToWebp.js +72 -114
- package/dist/lib/changeMetaInfo.d.ts +0 -6
- package/dist/lib/changeMetaInfo.js +0 -18
- package/dist/lib/toGif.d.ts +4 -1
- package/dist/lib/toGif.js +51 -26
- package/dist/types/StickerTypes.d.ts +3 -4
- package/dist/types/StickerTypes.js +3 -4
- package/dist/types/metaInfoType.d.ts +2 -3
- package/package.json +6 -2
- package/readme.md +2 -6
package/dist/index.js
CHANGED
|
@@ -57,6 +57,8 @@ var Sticker = /** @class */ (function () {
|
|
|
57
57
|
this.outBuffer = Buffer.from([]);
|
|
58
58
|
this.activeBuff = false;
|
|
59
59
|
this.activeMeta = false;
|
|
60
|
+
this.mimeType = '';
|
|
61
|
+
this.extType = '';
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
62
64
|
* Initializes the Sticker instance.
|
|
@@ -67,30 +69,29 @@ var Sticker = /** @class */ (function () {
|
|
|
67
69
|
Sticker.prototype.initialize = function () {
|
|
68
70
|
return __awaiter(this, void 0, void 0, function () {
|
|
69
71
|
var _a, fileType, error_1;
|
|
70
|
-
var _b, _c, _d, _e, _f, _g;
|
|
71
|
-
return __generator(this, function (
|
|
72
|
-
switch (
|
|
72
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
73
|
+
return __generator(this, function (_l) {
|
|
74
|
+
switch (_l.label) {
|
|
73
75
|
case 0:
|
|
74
|
-
|
|
76
|
+
_l.trys.push([0, 3, , 4]);
|
|
75
77
|
_a = this;
|
|
76
78
|
return [4 /*yield*/, this.utils.buffer(this.data)];
|
|
77
79
|
case 1:
|
|
78
|
-
_a.buffer =
|
|
80
|
+
_a.buffer = _l.sent();
|
|
79
81
|
return [4 /*yield*/, this.utils.getMimeType(this.buffer)];
|
|
80
82
|
case 2:
|
|
81
|
-
fileType =
|
|
82
|
-
this.mimeType = fileType === null || fileType === void 0 ? void 0 : fileType.mime;
|
|
83
|
-
this.extType = fileType === null || fileType === void 0 ? void 0 : fileType.ext;
|
|
84
|
-
this.metaInfo.pack = (
|
|
85
|
-
this.metaInfo.author = (
|
|
86
|
-
this.metaInfo.id = (
|
|
87
|
-
this.metaInfo.category = (
|
|
88
|
-
this.metaInfo.type = (
|
|
89
|
-
this.metaInfo.quality = (
|
|
90
|
-
this.metaInfo.background = this.metaInfo.background;
|
|
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);
|
|
91
92
|
return [3 /*break*/, 4];
|
|
92
93
|
case 3:
|
|
93
|
-
error_1 =
|
|
94
|
+
error_1 = _l.sent();
|
|
94
95
|
throw new Error("Initialization error: ".concat(error_1));
|
|
95
96
|
case 4: return [2 /*return*/];
|
|
96
97
|
}
|
|
@@ -103,25 +104,25 @@ var Sticker = /** @class */ (function () {
|
|
|
103
104
|
*/
|
|
104
105
|
Sticker.prototype.toBuffer = function () {
|
|
105
106
|
return __awaiter(this, void 0, void 0, function () {
|
|
106
|
-
var buffer,
|
|
107
|
-
return __generator(this, function (
|
|
108
|
-
switch (
|
|
107
|
+
var buffer, _a, error_2;
|
|
108
|
+
return __generator(this, function (_b) {
|
|
109
|
+
switch (_b.label) {
|
|
109
110
|
case 0:
|
|
110
|
-
|
|
111
|
+
_b.trys.push([0, 4, , 5]);
|
|
111
112
|
return [4 /*yield*/, this.initialize()];
|
|
112
113
|
case 1:
|
|
113
|
-
|
|
114
|
+
_b.sent();
|
|
114
115
|
return [4 /*yield*/, (0, ToWebp_js_1.default)(this.buffer, this.metaInfo, this.extType, this.mimeType)];
|
|
115
116
|
case 2:
|
|
116
|
-
buffer =
|
|
117
|
+
buffer = _b.sent();
|
|
118
|
+
_a = this;
|
|
117
119
|
return [4 /*yield*/, new changeMetaInfo_js_1.default(this.metaInfo).add(buffer)];
|
|
118
120
|
case 3:
|
|
119
|
-
|
|
121
|
+
_a.outBuffer = _b.sent();
|
|
120
122
|
this.activeBuff = true;
|
|
121
|
-
this.outBuffer = this.extType !== 'gif' ? MetaBuff : buffer;
|
|
122
123
|
return [2 /*return*/, this.outBuffer];
|
|
123
124
|
case 4:
|
|
124
|
-
error_2 =
|
|
125
|
+
error_2 = _b.sent();
|
|
125
126
|
this.activeBuff = false;
|
|
126
127
|
throw new Error("Conversion to buffer failed: ".concat(error_2));
|
|
127
128
|
case 5: return [2 /*return*/];
|
package/dist/lib/ToWebp.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { MetaDataType } from '../types/metaInfoType.js';
|
|
3
3
|
/**
|
|
4
|
-
* Converts
|
|
5
|
-
*
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
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
11
|
*/
|
|
12
|
-
declare const ToWebp: (buffer: Buffer, metaInfo: Partial<MetaDataType>, mimeExt: string
|
|
12
|
+
declare const ToWebp: (buffer: Buffer, metaInfo: Partial<MetaDataType>, mimeExt: string, mimeType: string) => Promise<Buffer>;
|
|
13
13
|
export default ToWebp;
|
package/dist/lib/ToWebp.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -39,132 +62,67 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
63
|
};
|
|
41
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
var
|
|
43
|
-
var path_1 = require("path");
|
|
44
|
-
var promises_1 = require("fs/promises");
|
|
45
|
-
var os_1 = require("os");
|
|
46
|
-
var util_1 = require("util");
|
|
65
|
+
var sharp_1 = __importStar(require("sharp"));
|
|
47
66
|
var StickerTypes_js_1 = require("../types/StickerTypes.js");
|
|
48
67
|
var toGif_js_1 = __importDefault(require("./toGif.js"));
|
|
49
|
-
var execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
50
68
|
/**
|
|
51
|
-
* Converts
|
|
52
|
-
*
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @
|
|
57
|
-
* @
|
|
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.
|
|
58
76
|
*/
|
|
59
77
|
var ToWebp = function (buffer, metaInfo, mimeExt, mimeType) { return __awaiter(void 0, void 0, void 0, function () {
|
|
60
|
-
var
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
switch (_d.label) {
|
|
78
|
+
var data, _a, isAnimated, res, error_1;
|
|
79
|
+
return __generator(this, function (_b) {
|
|
80
|
+
switch (_b.label) {
|
|
64
81
|
case 0:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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)];
|
|
68
87
|
case 1:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return [4 /*yield*/, (0, promises_1.writeFile)(inputPath, buffer)];
|
|
88
|
+
_a = _b.sent();
|
|
89
|
+
return [3 /*break*/, 3];
|
|
72
90
|
case 2:
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
return [4 /*yield*/, (0, toGif_js_1.default)(inputPath)];
|
|
91
|
+
_a = buffer;
|
|
92
|
+
_b.label = 3;
|
|
77
93
|
case 3:
|
|
78
|
-
|
|
79
|
-
|
|
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: mimeExt.includes('gif') ? false : true
|
|
119
|
+
})
|
|
120
|
+
.toBuffer()];
|
|
80
121
|
case 4:
|
|
81
|
-
|
|
82
|
-
_d.label = 5;
|
|
83
|
-
case 5:
|
|
84
|
-
inputPath = _a;
|
|
85
|
-
args = [
|
|
86
|
-
'-i',
|
|
87
|
-
inputPath,
|
|
88
|
-
metaInfo.type === StickerTypes_js_1.StickerTypes.CIRCLE && !metaInfo.background
|
|
89
|
-
? StickerTypes_js_1.StickerTypes.CIRCLE
|
|
90
|
-
: metaInfo.type === StickerTypes_js_1.StickerTypes.SQUARE && !metaInfo.background
|
|
91
|
-
? StickerTypes_js_1.StickerTypes.SQUARE
|
|
92
|
-
: metaInfo.type === StickerTypes_js_1.StickerTypes.FIT && !metaInfo.background
|
|
93
|
-
? StickerTypes_js_1.StickerTypes.FIT
|
|
94
|
-
: '',
|
|
95
|
-
metaInfo.background
|
|
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
|
-
metaInfo.type === StickerTypes_js_1.StickerTypes.SQUARE ||
|
|
98
|
-
metaInfo.type === StickerTypes_js_1.StickerTypes.FIT
|
|
99
|
-
? ", ".concat(metaInfo.type.replace(/-vf/g, '').replace(/"/g, '').replace('-filter_complex', '').trim())
|
|
100
|
-
: '', "\"")
|
|
101
|
-
: '-pix_fmt yuva420p',
|
|
102
|
-
(mimeExt === null || mimeExt === void 0 ? void 0 : mimeExt.includes('gif')) || (mimeType === null || mimeType === void 0 ? void 0 : mimeType.includes('video'))
|
|
103
|
-
? [
|
|
104
|
-
'-c:v libwebp_anim',
|
|
105
|
-
'-auto-alt-ref 0',
|
|
106
|
-
'-lag-in-frames 0',
|
|
107
|
-
'-preset default',
|
|
108
|
-
'-t 10',
|
|
109
|
-
'-loop 0',
|
|
110
|
-
].join(' ')
|
|
111
|
-
: '-c:v libwebp',
|
|
112
|
-
'-q:v',
|
|
113
|
-
(_c = (_b = metaInfo.quality) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : '50',
|
|
114
|
-
'-y',
|
|
115
|
-
outputPath
|
|
116
|
-
];
|
|
117
|
-
//console.log(args.join(" "))
|
|
118
|
-
// Execute ffmpeg command with constructed arguments
|
|
119
|
-
return [4 /*yield*/, execAsync("ffmpeg ".concat(args.join(' ')))
|
|
120
|
-
// Read converted WebP file back into a buffer
|
|
121
|
-
];
|
|
122
|
-
case 6:
|
|
123
|
-
//console.log(args.join(" "))
|
|
124
|
-
// Execute ffmpeg command with constructed arguments
|
|
125
|
-
_d.sent();
|
|
126
|
-
return [4 /*yield*/, (0, promises_1.readFile)(outputPath)];
|
|
127
|
-
case 7:
|
|
128
|
-
outputBuffer = _d.sent();
|
|
129
|
-
return [2 /*return*/, outputBuffer];
|
|
130
|
-
case 8:
|
|
131
|
-
error_1 = _d.sent();
|
|
132
|
-
console.error("Conversion error: ".concat(error_1));
|
|
122
|
+
error_1 = _b.sent();
|
|
133
123
|
throw new Error("Conversion failed: ".concat(error_1));
|
|
134
|
-
case
|
|
135
|
-
// Cleanup temporary files
|
|
136
|
-
return [4 /*yield*/, cleanup(inputPath, outputPath).catch(function (e) { return console.error(e); })];
|
|
137
|
-
case 10:
|
|
138
|
-
// Cleanup temporary files
|
|
139
|
-
_d.sent();
|
|
140
|
-
return [7 /*endfinally*/];
|
|
141
|
-
case 11: return [2 /*return*/];
|
|
124
|
+
case 5: return [2 /*return*/];
|
|
142
125
|
}
|
|
143
126
|
});
|
|
144
127
|
}); };
|
|
145
|
-
/**
|
|
146
|
-
* Cleans up temporary files used during conversion.
|
|
147
|
-
* @param inputPath Path to the input temporary file.
|
|
148
|
-
* @param outputPath Path to the output temporary file.
|
|
149
|
-
*/
|
|
150
|
-
function cleanup(inputPath, outputPath) {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
152
|
-
var unlinkError_1;
|
|
153
|
-
return __generator(this, function (_a) {
|
|
154
|
-
switch (_a.label) {
|
|
155
|
-
case 0:
|
|
156
|
-
_a.trys.push([0, 2, , 3]);
|
|
157
|
-
return [4 /*yield*/, Promise.all([(0, promises_1.unlink)(inputPath), (0, promises_1.unlink)(outputPath)])];
|
|
158
|
-
case 1:
|
|
159
|
-
_a.sent();
|
|
160
|
-
return [3 /*break*/, 3];
|
|
161
|
-
case 2:
|
|
162
|
-
unlinkError_1 = _a.sent();
|
|
163
|
-
console.error('Error cleaning output file:', unlinkError_1);
|
|
164
|
-
return [3 /*break*/, 3];
|
|
165
|
-
case 3: return [2 /*return*/];
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
128
|
exports.default = ToWebp;
|
|
@@ -24,10 +24,4 @@ export default class Exif {
|
|
|
24
24
|
* @returns A Promise that resolves to a Buffer containing the image with the added Exif data.
|
|
25
25
|
*/
|
|
26
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
27
|
}
|
|
@@ -113,24 +113,6 @@ var Exif = /** @class */ (function () {
|
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
}); };
|
|
116
|
-
/**
|
|
117
|
-
* Loads the image from a Buffer or string and returns an Image instance.
|
|
118
|
-
* @param image - A Buffer or string representing the image to be loaded.
|
|
119
|
-
* @returns A Promise that resolves to an Image instance.
|
|
120
|
-
*/
|
|
121
|
-
this.load = function (image) { return __awaiter(_this, void 0, void 0, function () {
|
|
122
|
-
var img;
|
|
123
|
-
return __generator(this, function (_a) {
|
|
124
|
-
switch (_a.label) {
|
|
125
|
-
case 0:
|
|
126
|
-
img = new node_webpmux_1.default.Image();
|
|
127
|
-
return [4 /*yield*/, img.load(image)];
|
|
128
|
-
case 1:
|
|
129
|
-
_a.sent();
|
|
130
|
-
return [2 /*return*/, img];
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}); };
|
|
134
116
|
this.data['sticker-pack-id'] = options.id || '';
|
|
135
117
|
this.data['sticker-pack-name'] = options.pack || '';
|
|
136
118
|
this.data['sticker-pack-publisher'] = options.author || '';
|
package/dist/lib/toGif.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
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;
|
package/dist/lib/toGif.js
CHANGED
|
@@ -35,33 +35,58 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
38
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
function
|
|
45
|
-
return __awaiter(
|
|
46
|
-
var
|
|
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;
|
|
47
50
|
return __generator(this, function (_a) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
_a
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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);
|
|
63
87
|
}
|
|
88
|
+
return [2 /*return*/];
|
|
64
89
|
});
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
exports.default =
|
|
90
|
+
}); });
|
|
91
|
+
};
|
|
92
|
+
exports.default = videoToGif;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export declare enum StickerTypes {
|
|
2
|
-
DEFAULT =
|
|
3
|
-
SQUARE =
|
|
4
|
-
CIRCLE =
|
|
5
|
-
FIT = "-vf \"scale=iw*min(200/iw\\,200/ih):ih*min(200/iw\\,200/ih),pad=200:200:(200-iw*min(200/iw\\,200/ih))/2:(200-ih*min(200/iw\\,200/ih))/2\""
|
|
2
|
+
DEFAULT = 0,
|
|
3
|
+
SQUARE = 1,
|
|
4
|
+
CIRCLE = 2
|
|
6
5
|
}
|
|
@@ -3,8 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.StickerTypes = void 0;
|
|
4
4
|
var StickerTypes;
|
|
5
5
|
(function (StickerTypes) {
|
|
6
|
-
StickerTypes["DEFAULT"] = "";
|
|
7
|
-
StickerTypes["SQUARE"] =
|
|
8
|
-
StickerTypes["CIRCLE"] =
|
|
9
|
-
StickerTypes["FIT"] = "-vf \"scale=iw*min(200/iw\\,200/ih):ih*min(200/iw\\,200/ih),pad=200:200:(200-iw*min(200/iw\\,200/ih))/2:(200-ih*min(200/iw\\,200/ih))/2\"";
|
|
6
|
+
StickerTypes[StickerTypes["DEFAULT"] = 0] = "DEFAULT";
|
|
7
|
+
StickerTypes[StickerTypes["SQUARE"] = 1] = "SQUARE";
|
|
8
|
+
StickerTypes[StickerTypes["CIRCLE"] = 2] = "CIRCLE";
|
|
10
9
|
})(StickerTypes || (exports.StickerTypes = StickerTypes = {}));
|
|
@@ -3,9 +3,8 @@ import { StickerTypes } from './StickerTypes.js';
|
|
|
3
3
|
export interface MetaDataType {
|
|
4
4
|
pack?: string;
|
|
5
5
|
author?: string;
|
|
6
|
-
id?: string
|
|
6
|
+
id?: string;
|
|
7
7
|
category?: category[];
|
|
8
|
-
type?: StickerTypes
|
|
8
|
+
type?: StickerTypes;
|
|
9
9
|
quality?: number;
|
|
10
|
-
background?: String | undefined;
|
|
11
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shibam/sticker-maker",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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
|
-
"
|
|
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/
|
|
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
|
|