| 169 | } |
| 170 | } |
| 171 | async function forceMiniSticker(inputBuffer, isVideo, cropSquare) { |
| 172 | const tmpDir = path.join(process.cwd(), 'temp'); |
| 173 | if (!fs.existsSync(tmpDir)) |
| 174 | fs.mkdirSync(tmpDir, { recursive: true }); |
| 175 | const tempInput = path.join(tmpDir, `mini_${Date.now()}.${isVideo ? 'mp4' : 'jpg'}`); |
| 176 | const tempOutput = path.join(tmpDir, `mini_out_${Date.now()}.webp`); |
| 177 | fs.writeFileSync(tempInput, inputBuffer); |
| 178 | const vf = cropSquare |
| 179 | ? `crop=min(iw\\,ih):min(iw\\,ih),scale=256:256${isVideo ? ',fps=6' : ''}` |
| 180 | : `scale=256:256:force_original_aspect_ratio=decrease,pad=256:256:(ow-iw)/2:(oh-ih)/2:color=#00000000${isVideo ? ',fps=6' : ''}`; |
| 181 | const cmd = `ffmpeg -y -i "${tempInput}" ${isVideo ? '-t 2' : ''} -vf "${vf}" -c:v libwebp -preset default -loop 0 -pix_fmt yuva420p -quality 10 -compression_level 6 -b:v 40k "${tempOutput}"`; |
| 182 | await new Promise((resolve, reject) => { |
| 183 | exec(cmd, (error) => error ? reject(error) : resolve(undefined)); |
| 184 | }); |
| 185 | if (!fs.existsSync(tempOutput)) { |
| 186 | try { |
| 187 | fs.unlinkSync(tempInput); |
| 188 | } |
| 189 | catch { } |
| 190 | return null; |
| 191 | } |
| 192 | const smallWebp = fs.readFileSync(tempOutput); |
| 193 | const img = new webp.Image(); |
| 194 | await img.load(smallWebp); |
| 195 | const json = { |
| 196 | 'sticker-pack-id': crypto.randomBytes(32).toString('hex'), |
| 197 | 'sticker-pack-name': config.packname || 'MegaBot', |
| 198 | 'emojis': ['📸'] |
| 199 | }; |
| 200 | const exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00]); |
| 201 | const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8'); |
| 202 | const exif = Buffer.concat([exifAttr, jsonBuffer]); |
| 203 | exif.writeUIntLE(jsonBuffer.length, 14, 4); |
| 204 | img.exif = exif; |
| 205 | const finalBuffer = await img.save(null); |
| 206 | try { |
| 207 | fs.unlinkSync(tempInput); |
| 208 | } |
| 209 | catch { } |
| 210 | try { |
| 211 | fs.unlinkSync(tempOutput); |
| 212 | } |
| 213 | catch { } |
| 214 | return finalBuffer; |
| 215 | } |
| 216 | export default { |
| 217 | command: 'igs', |
| 218 | aliases: ['igsticker', 'instasticker'], |