make image loading work even in compiled version (?)

This commit is contained in:
Tomáš Mládek 2021-09-15 21:16:01 +02:00
parent a656d37d8c
commit 1ba396bc7c

View file

@ -1,10 +1,6 @@
import { parse } from "https://deno.land/std@0.106.0/flags/mod.ts";
import { createCanvas, loadImage } from "https://deno.land/x/canvas/mod.ts";
import {
CollageModes,
CollageModeType,
collageModeType,
} from "../src/common/collages.ts";
import { createCanvas, init } from "https://deno.land/x/canvas/mod.ts";
import { CollageModeType, collageModeType } from "../src/common/collages.ts";
import DenoCollageModes, {
CastCanvasRenderingContext,
ProxyImage,
@ -12,22 +8,28 @@ import DenoCollageModes, {
import { CollageConfig } from "../src/common/types.ts";
import { choice, shuffle } from "../src/common/utils.ts";
const canvasKit = await init();
const args = parse(Deno.args, {
alias: {
"w": "width",
"h": "height",
"o": "output",
"m": "mode",
},
});
const images: ProxyImage[] =
(await Promise.all(
args["_"].map((imageURL) => loadImage(imageURL.toString())),
)).map((image) => new ProxyImage(image));
if (images.length < 2) {
if (args["_"].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()))
),
)).map((image) => new ProxyImage(image!));
const modes = new DenoCollageModes();
const modeKey: CollageModeType = args["mode"] || choice(collageModeType);