-
Notifications
You must be signed in to change notification settings - Fork 432
Description
I am using this library to remove background from a picture which i am first resizing using sharp. Everything works fine in the local development, but when i use the deployed backend on render, everything works till resizing after which upon reaching the remove background code my server gets killed on render and i get a 502 error.


This is my code
const config = {
debug: true, // enable or disable useful console.log outputs
device: "cpu", // choose the execution device. gpu will use webgpu if available
proxyToWorker: true, // Whether to proxy the calculations to a web worker. (Default true)
model: "medium", // The model to use. (Default "isnet_fp16")
output: {
format: "image/png", // The output format. (Default "image/png")
quality: 1, // The quality. (Default: 0.8)
type: "foreground", // The output type. 'foreground' | 'background' | 'mask' (Default "foreground")
},
};
exports.removeBg = catchAsync(async (req, res, next) => {
const url = req.query.imgURL;
if (!url) {
return next(new ErrorHandler("Image URL not found", 404));
}
const resizedImg = await resizeImage(url, 200);
if (!resizedImg) {
return next(new ErrorHandler("Error resizing image", 500));
}
const blob = new Blob([resizedImg], { type: "image/png" });
const result = await removeBackground(blob, config);
if (!result) {
return next(new ErrorHandler("Error removing background", 500));
}
const base64 = Buffer.from(await result.arrayBuffer()).toString("base64");
const imgUrl = await uploadImage(data:image/png;base64,${base64}
);
res.status(201).json({
status: "success",
imgUrl,
});
});