kollagen/cli/collages.ts

45 lines
1,021 B
TypeScript
Raw Normal View History

2021-09-15 21:19:03 +02:00
import { CollageModes } from "../src/common/collages.ts";
import {
CanvasRenderingContext2D,
Image,
} from "https://deno.land/x/canvas/mod.ts";
import { CollageContext, CollageImage } from "../src/common/types.ts";
export class ProxyImage implements CollageImage {
2021-09-15 21:19:03 +02:00
private image: Image;
public readonly height: number;
public readonly width: number;
2021-09-15 21:19:03 +02:00
constructor(image: Image) {
this.image = image;
this.width = image.width();
this.height = image.height();
}
2021-09-15 21:19:03 +02:00
public get(): Image {
return this.image;
}
}
2021-09-15 21:19:03 +02:00
export type CastCanvasRenderingContext =
& CanvasRenderingContext2D
& CollageContext;
2021-09-15 21:19:03 +02:00
export default class BrowserCollageModes
extends CollageModes<CastCanvasRenderingContext, ProxyImage> {
drawImage(
ctx: CastCanvasRenderingContext,
image: ProxyImage,
sx: number,
sy: number,
sw: number,
sh: number,
dx: number,
dy: number,
dw: number,
dh: number,
): void {
ctx.drawImage(image.get(), sx, sy, sw, sh, dx, dy, dw, dh);
}
}