fix canvas version mismatch breaking build
This commit is contained in:
parent
f004daaa3c
commit
f24047b33b
1 changed files with 6 additions and 8 deletions
|
@ -1,11 +1,11 @@
|
||||||
import { CollageModes } from "../src/common/collages.ts";
|
import { CollageModes } from "../src/common/collages.ts";
|
||||||
import {
|
import {
|
||||||
|
init,
|
||||||
CanvasRenderingContext2D,
|
CanvasRenderingContext2D,
|
||||||
EmulatedCanvas2D,
|
EmulatedCanvas2D,
|
||||||
Image,
|
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 { CollageImage } from "../src/common/types.ts";
|
||||||
import { init } from "https://deno.land/x/canvas@v1.3.0/mod.ts";
|
|
||||||
|
|
||||||
const canvasKit = await init();
|
const canvasKit = await init();
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ export class ProxyImage implements CollageImage {
|
||||||
public get image(): Image {
|
public get image(): Image {
|
||||||
if (!this._image) {
|
if (!this._image) {
|
||||||
const image = canvasKit.MakeImageFromEncoded(
|
const image = canvasKit.MakeImageFromEncoded(
|
||||||
Deno.readFileSync(this.filepath!),
|
Deno.readFileSync(this.filepath!)
|
||||||
);
|
);
|
||||||
if (!image) {
|
if (!image) {
|
||||||
throw Error(`Failed loading ${this.filepath}!`);
|
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 {
|
interface HTMLCanvasElement {
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
|
@ -70,9 +70,7 @@ export class DenoCollageModes extends CollageModes<
|
||||||
}
|
}
|
||||||
|
|
||||||
canvasToImage(canvas: EmulatedCanvas2D): PromiseLike<ProxyImage> {
|
canvasToImage(canvas: EmulatedCanvas2D): PromiseLike<ProxyImage> {
|
||||||
const image = canvasKit.MakeImageFromEncoded(
|
const image = canvasKit.MakeImageFromEncoded(canvas.toBuffer());
|
||||||
canvas.toBuffer(),
|
|
||||||
);
|
|
||||||
if (!image) {
|
if (!image) {
|
||||||
throw Error("Something went wrong converting canvas to image.");
|
throw Error("Something went wrong converting canvas to image.");
|
||||||
}
|
}
|
||||||
|
@ -89,7 +87,7 @@ export class DenoCollageModes extends CollageModes<
|
||||||
dx: number,
|
dx: number,
|
||||||
dy: number,
|
dy: number,
|
||||||
dw: number,
|
dw: number,
|
||||||
dh: number,
|
dh: number
|
||||||
): void {
|
): void {
|
||||||
ctx.drawImage(image.image, sx, sy, sw, sh, dx, dy, dw, dh);
|
ctx.drawImage(image.image, sx, sy, sw, sh, dx, dy, dw, dh);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue