MCPcopy Create free account
hub / github.com/Xchristech2/Zenitsu-Bot / imageToWebp

Function imageToWebp

lib/exif.js:20–45  ·  view source on GitHub ↗
(media)

Source from the content-addressed store, hash-verified

18
19
20async function imageToWebp (media) {
21
22 const tmpFileOut = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.webp`)
23 const tmpFileIn = path.join(tmpdir(), `${Crypto.randomBytes(6).readUIntLE(0, 6).toString(36)}.jpg`)
24
25 fs.writeFileSync(tmpFileIn, media)
26
27 await new Promise((resolve, reject) => {
28 ff(tmpFileIn)
29 .on("error", reject)
30 .on("end", () => resolve(true))
31 .addOutputOptions([
32 "-vcodec",
33 "libwebp",
34 "-vf",
35 "scale='min(320,iw)':min'(320,ih)':force_original_aspect_ratio=decrease,fps=15, pad=320:320:-1:-1:color=white@0.0, split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse"
36 ])
37 .toFormat("webp")
38 .save(tmpFileOut)
39 })
40
41 const buff = fs.readFileSync(tmpFileOut)
42 fs.unlinkSync(tmpFileOut)
43 fs.unlinkSync(tmpFileIn)
44 return buff
45}
46
47async function videoToWebp (media) {
48

Callers 2

writeExifImgFunction · 0.85
writeExifFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected