-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupScale.js
33 lines (32 loc) · 945 Bytes
/
upScale.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
const axios = require("axios");
const path = require("path");
const fs = require("fs");
module.exports.upScale = function upScale(respImage, fileName) {
var upScaleData = JSON.stringify({
"image": respImage.toString(),
"upscaling_resize": 4,
"upscaling_crop": false,
"upscaler_1": "SwinIR_4x"
});
const upScalerConfig = {
method: 'post',
url: 'http://127.0.0.1:7860/sdapi/v1/extra-single-image',
headers: {
'Content-Type': 'application/json'
},
data: upScaleData
};
async function upScaleImg() {
try {
console.log("Upscaling Img");
const upScaleResp = await axios(upScalerConfig);
const { image } = upScaleResp.data;
const bufferUpScale = Buffer.from(image, "base64");
const upScalePath = path.join("upScale", `${fileName}.png`);
fs.writeFileSync(upScalePath, bufferUpScale);
} catch (e) {
console.log("Error", e);
}
}
upScaleImg();
}