27 lines
718 B
TypeScript
27 lines
718 B
TypeScript
import type { ToolInput } from "../../core/io/input-types";
|
|
import type { ToolResult } from "../../core/io/output-types";
|
|
import type { ToolContext } from "../../core/plugins/plugin-types";
|
|
import { removeImageBackground, type BackgroundRemoverOptions } from "./remove";
|
|
|
|
export async function runBackgroundRemover(
|
|
input: ToolInput,
|
|
options: BackgroundRemoverOptions,
|
|
context: ToolContext
|
|
): Promise<ToolResult> {
|
|
const files = input.files;
|
|
|
|
if (!files || !Array.isArray(files) || files.length === 0) {
|
|
throw new Error("No image provided.");
|
|
}
|
|
|
|
const file = files[0];
|
|
|
|
return removeImageBackground(
|
|
file.name,
|
|
file,
|
|
options,
|
|
self.location.origin,
|
|
context.reportProgress
|
|
);
|
|
}
|