MCPcopy Create free account
hub / github.com/Maccoder3/MAC-MD / sticker2

Function sticker2

lib/sticker.js:22–64  ·  view source on GitHub ↗

* Image to Sticker * @param {Buffer} img Image Buffer * @param {String} url Image URL

(img, url)

Source from the content-addressed store, hash-verified

20 * @param {String} url Image URL
21 */
22function sticker2(img, url) {
23 return new Promise(async (resolve, reject) => {
24 try {
25 if (url) {
26 let res = await fetch(url)
27 if (res.status !== 200) throw await res.text()
28 img = await res.buffer()
29 }
30 let inp = path.join(tmp, +new Date() + '.jpeg')
31 await fs.promises.writeFile(inp, img)
32 let ff = spawn('ffmpeg', [
33 '-y',
34 '-i',
35 inp,
36 '-vf',
37 'scale=512:512:flags=lanczos:force_original_aspect_ratio=decrease,format=rgba,pad=512:512:(ow-iw)/2:(oh-ih)/2:color=#00000000,setsar=1',
38 '-f',
39 'png',
40 '-',
41 ])
42 ff.on('error', reject)
43 ff.on('close', async () => {
44 await fs.promises.unlink(inp)
45 })
46 let bufs = []
47 const [_spawnprocess, ..._spawnargs] = [
48 ...(module.exports.support.gm ? ['gm'] : module.exports.magick ? ['magick'] : []),
49 'convert',
50 'png:-',
51 'webp:-',
52 ]
53 let im = spawn(_spawnprocess, _spawnargs)
54 im.on('error', e => conn.reply(m.chat, util.format(e), m))
55 im.stdout.on('data', chunk => bufs.push(chunk))
56 ff.stdout.pipe(im.stdin)
57 im.on('exit', () => {
58 resolve(Buffer.concat(bufs))
59 })
60 } catch (e) {
61 reject(e)
62 }
63 })
64}
65
66/**
67 * Image/Video to Sticker

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected