Back to Library
Upscale Image
js • 1/27/2026
20
const axios = require("axios");
const FormData = require("form-data");
async function fetchBuffer(url) {
try {
const response = await axios.get(url, { responseType: 'arraybuffer' });
return Buffer.from(response.data);
} catch (error) {
throw new Error("Failed to download image");
}
}
async function upscale(url) {
try {
const buffer = await fetchBuffer(url);
const form = new FormData();
form.append("image", buffer, { filename: "image.jpg" });
form.append("scale", "2");
const headers = {
...form.getHeaders(),
"accept": "application/json",
"x-client-version": "web",
"x-locale": "en",
};
const res = await axios.post("https://api2.pixelcut.app/image/upscale/v1", form, { headers });
const json = res.data;
if (!json.result_url) {
throw new Error("Failed to get result URL");
}
const resultBuffer = await fetchBuffer(json.result_url);
return resultBuffer;
} catch (error) {
throw new Error(error.message);
}
}
module.exports = { upscale };