-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: ReferenceError: Response is not defined #109
Comments
Hi !! |
Cause: Response is used in the package, but is not imported.
|
There is a more reasonable solution :) import { removeBackground } from "@imgly/background-removal-node";
import fs from "fs";
// here
import { Response, Blob } from "node-fetch";
globalThis.Response = Response;
globalThis.Blob = Blob;
const image_src = "./1_9it-TQH191NXVvKqv4dF1A.webp";
async function removeImageBackground(imgSource) {
const blob = await removeBackground(imgSource, {
model: "medium",
progress: (progress, current, total) => {
const currentProgress = (current / total) * 100;
console.log(progress, `Progress: ${currentProgress.toFixed(2)}%`);
},
});
const buffer = Buffer.from(await blob.arrayBuffer());
const dataURL = `data:image/png;base64,${buffer.toString("base64")}`;
return dataURL;
}
removeImageBackground(image_src)
.then((dataURL) => {
fs.writeFileSync("output.png", dataURL.split(";base64,").pop(), {
encoding: "base64",
});
})
.catch((error) => {
console.error(error);
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm using @imgly/background-removal-node package for an example.
But I get the error: ReferenceError: Response is not defined
Following is my example
How to resolve this? Please
The text was updated successfully, but these errors were encountered: