-
Notifications
You must be signed in to change notification settings - Fork 335
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: Unsupported protocol: c: #112
Comments
Same here, seems like its absolute path problem. Code// Relative Path
console.log("Removing:", "./img/background.jpg");
await removeBackground(path.join("./img/background.jpg"), config);
console.log("Success");
// Absolute Path
console.log("Removing:", path.join(process.cwd(), "img", "background.jpg"));
await removeBackground(
path.join(process.cwd(), "img", "background.jpg"),
config
);
console.log("Success"); Output
|
Same issue here. Unfortunately I seem to need the absolute path for the distributed Electron app. Help please? |
Hi @JPhilipp, I've found a fix for it. You may try reading the file yourself and pass the data to import { removeBackground, Config } from "@imgly/background-removal-node";
export default async function localRemoveBgServices(
imageBuffer: Buffer // The imageBuffer is read somewhere with fs.readFileSync(...);
): Promise<Buffer> {
let config: Config = {
output: { format: "image/png" },
};
const blob = new Blob([imageBuffer], { type: "image/jpeg" });
const removedBackground = await removeBackground(blob, config);
return Buffer.from(await removedBackground.arrayBuffer());
} |
Thank you, I will try that! |
Strange. I now switched to the suggested blob passing, and it all works fine in the dev version, but again when I run it from the distribution, it doesn't generate the image. Even though the image with background saves fine in the distribution at the same foo.png path instead of foo-background-removed.png path. I'm so confused.
|
Would it probably because of the |
I think it's a problem with the Asset Resolver which dispatches based on URIs and it tries to parse the path as URI, as such "C" becomes the protocol. I have no windows machine to debug that case atm. |
This is the root cause I think:
|
const fs = require("fs");
const { removeBackground } = require("@imgly/background-removal-node");
async function saveBlobToDisk(blob, outputPath) {
try {
const buffer = Buffer.from(await blob.arrayBuffer());
fs.writeFileSync(outputPath, buffer);
console.log("File saved successfully:", outputPath);
return 0;
} catch (error) {
console.error("Error saving file:", error);
return 1;
}
}
async function remove(imgSource, outputPath) {
try {
let blob = await removeBackground(imgSource);
await saveBlobToDisk(blob, outputPath);
} catch (error) {
console.error("Error removing background:", error);
}
}
remove(
"C:/Users/milanahir227/Desktop/background image/public/test.jpg",
"C:/Users/milanahir227/Desktop/background image/public/output.png"
);
in this code when run with node then gave me this like error
Error =>
Error removing background: Error: Unsupported protocol: c:
at loadFromURI (C:\Users\milanahir227\Desktop\js\node_modules@imgly\background-removal-node\dist\index.cjs:174:13)
at imageSourceToImageData (C:\Users\milanahir227\Desktop\js\node_modules@imgly\background-removal-node\dist\index.cjs:271:26)
at removeBackground (C:\Users\milanahir227\Desktop\js\node_modules@imgly\background-removal-node\dist\index.cjs:505:29)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async remove (C:\Users\milanahir227\Desktop\js\imagetoarrbuffer.js:18:16)
The text was updated successfully, but these errors were encountered: