clamp cli to 25 images for performance reasons

This commit is contained in:
Tomáš Mládek 2021-09-17 19:09:51 +02:00
parent 57f32ef643
commit eb455e2311

View file

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