(media)
| 18 | |
| 19 | |
| 20 | async 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 | |
| 47 | async function videoToWebp (media) { |
| 48 |
no outgoing calls
no test coverage detected