clamp cli to 25 images for performance reasons

master
Tomáš Mládek 2021-09-17 19:09:51 +02:00
parent 57f32ef643
commit eb455e2311
1 changed files with 11 additions and 5 deletions

View File

@ -37,8 +37,15 @@ if (files.length < 2) {
Deno.exit(1);
}
const shuffledFiles = shuffle(files);
if (shuffledFiles.length > 25) {
console.debug(`Too many files available, shuffling and clamping to 25...`);
shuffledFiles.splice(25, shuffledFiles.length - 25);
}
const images: ProxyImage[] = (await Promise.all(
files.map(async (imageURL) =>
shuffledFiles.map(async (imageURL) =>
canvasKit.MakeImageFromEncoded(await Deno.readFile(imageURL))
),
)).map((image) => new ProxyImage(image!));
@ -49,7 +56,7 @@ const modeKey: CollageModeType = args["mode"] || choice(collageModeType);
const mode = modes.modes[modeKey];
console.log(
`Creating a "${mode.name}" collage from ${images.length} images...`,
`Creating a "${mode.name}" collage...`,
);
console.debug(`Images: ${files.join(", ")}`);
@ -60,13 +67,12 @@ const collageConfig: CollageConfig = {
numImages: args["n"],
};
const shuffledImages = shuffle(images);
const segments = mode.getSegments(
context as CastCanvasRenderingContext,
collageConfig,
shuffledImages,
images,
);
mode.place(context as CastCanvasRenderingContext, shuffledImages, segments);
mode.place(context as CastCanvasRenderingContext, images, segments);
const output = args["output"] || "collage.png";
console.log(`Saving to "${output}"...`);