diff --git a/cli/main.ts b/cli/main.ts index e0bb0de..db042ac 100644 --- a/cli/main.ts +++ b/cli/main.ts @@ -19,14 +19,27 @@ const args = parse(Deno.args, { }, }); -if (args["_"].length < 2) { +const files: string[] = []; + +args["_"].forEach((arg) => { + arg = arg.toString(); + if (Deno.statSync(arg).isDirectory) { + Array.from(Deno.readDirSync(arg)).forEach((entry) => + files.push(`${arg}/${entry.name}`) + ); + } else { + files.push(arg); + } +}); + +if (files.length < 2) { console.error("kollagen needs at least 2 images to work."); Deno.exit(1); } const images: ProxyImage[] = (await Promise.all( - args["_"].map(async (imageURL) => - canvasKit.MakeImageFromEncoded(await Deno.readFile(imageURL.toString())) + files.map(async (imageURL) => + canvasKit.MakeImageFromEncoded(await Deno.readFile(imageURL)) ), )).map((image) => new ProxyImage(image!)); @@ -38,7 +51,7 @@ const mode = modes.modes[modeKey]; console.log( `Creating a "${mode.name}" collage from ${images.length} images...`, ); -console.debug(`Images: ${args["_"].join(", ")}`); +console.debug(`Images: ${files.join(", ")}`); const canvas = createCanvas(args["width"] || 640, args["height"] || 640); const context = canvas.getContext("2d");