File size: 766 Bytes
2b1b989
22ebc43
2b1b989
22ebc43
 
2b1b989
6670a11
 
8e129e0
6670a11
b73d0bc
6670a11
 
 
b73d0bc
6670a11
64726e1
6670a11
2b1b989
 
6670a11
2b1b989
 
6670a11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sharp from "sharp";
import fetch from "node-fetch";

function convertWebpToPng(input) {
  return new Promise(async(resolve, reject) => {
    try {
      if (typeof input === "string") {
        const response = await fetch(input);
        const images = await response.arrayBuffer();
        const converting = await sharp(images);
        const converted = await converting.toFormat('png').png({ quality: 90 }).toBuffer();
        resolve(converted);
      } else if (typeof input === "object") {
        const converting = await sharp(input);
        const converted = await converting.toFormat('png').png({ quality: 90 }).toBuffer();
        resolve(converted);
      }
    } catch (e) {
      reject(e.message);
    }
  });
}

export { convertWebpToPng };