fix canvas version mismatch breaking build

This commit is contained in:
Tomáš Mládek 2022-01-19 20:52:02 +01:00
parent f004daaa3c
commit f24047b33b
No known key found for this signature in database
GPG key ID: ED21612889E75EC5

View file

@ -1,11 +1,11 @@
import { CollageModes } from "../src/common/collages.ts";
import {
init,
CanvasRenderingContext2D,
EmulatedCanvas2D,
Image,
} from "https://deno.land/x/canvas/mod.ts";
} from "https://deno.land/x/canvas@v1.3.0/mod.ts";
import { CollageImage } from "../src/common/types.ts";
import { init } from "https://deno.land/x/canvas@v1.3.0/mod.ts";
const canvasKit = await init();
@ -29,7 +29,7 @@ export class ProxyImage implements CollageImage {
public get image(): Image {
if (!this._image) {
const image = canvasKit.MakeImageFromEncoded(
Deno.readFileSync(this.filepath!),
Deno.readFileSync(this.filepath!)
);
if (!image) {
throw Error(`Failed loading ${this.filepath}!`);
@ -48,7 +48,7 @@ export class ProxyImage implements CollageImage {
}
}
declare module "https://deno.land/x/canvas/mod.ts" {
declare module "https://deno.land/x/canvas@v1.3.0/mod.ts" {
interface HTMLCanvasElement {
width: number;
height: number;
@ -70,9 +70,7 @@ export class DenoCollageModes extends CollageModes<
}
canvasToImage(canvas: EmulatedCanvas2D): PromiseLike<ProxyImage> {
const image = canvasKit.MakeImageFromEncoded(
canvas.toBuffer(),
);
const image = canvasKit.MakeImageFromEncoded(canvas.toBuffer());
if (!image) {
throw Error("Something went wrong converting canvas to image.");
}
@ -89,7 +87,7 @@ export class DenoCollageModes extends CollageModes<
dx: number,
dy: number,
dw: number,
dh: number,
dh: number
): void {
ctx.drawImage(image.image, sx, sy, sw, sh, dx, dy, dw, dh);
}