cli takes directories as well as files
This commit is contained in:
parent
cd76a36d99
commit
57f32ef643
1 changed files with 17 additions and 4 deletions
21
cli/main.ts
21
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");
|
||||
|
|
Loading…
Reference in a new issue