-
Notifications
You must be signed in to change notification settings - Fork 1
/
macrophilia.js
40 lines (36 loc) · 873 Bytes
/
macrophilia.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const httpsGet = require('./httpsGet');
const sharp = require("sharp");
const { writeFile } = require("fs").promises
const macrophilia = ({ pathOpts, skipFs, withoutPrefix, height, mustBeThiqq, imgSource }) =>
new Promise(async (resolve, reject) => {
const image = await httpsGet({
imgSource,
withoutPrefix: true,
skipFs: true,
})
.catch(e => reject(e))
const buf = Buffer.from(image, "base64")
return await sharp(buf)
.resize({
height,
})
.png(mustBeThiqq ?
{
quality: 100,
compressionLevel: 0,
effort: 1
}
:
{}
)
.toBuffer()
.then(res => {
if (!skipFs) {
writeFile(pathOpts, res, "base64");
}
const b64Waifu = res.toString("base64");
resolve(withoutPrefix ? b64Waifu : `data:image/png;base64,${b64Waifu}`);
})
.catch(e => reject(e))
})
module.exports = macrophilia;