Preparations to support canvas el as argument

This commit is contained in:
2025-01-24 20:38:52 +01:00
parent 159a00599f
commit e01b849ea4

View File

@@ -34,12 +34,21 @@ class CanvasImage {
height: number;
constructor ( image: HTMLImageElement ) {
this.canvas = document.createElement( 'canvas' );
this.context = this.canvas.getContext( '2d' );
this.width = this.canvas.width = image.naturalWidth;
this.height = this.canvas.height = image.naturalHeight;
this.context.drawImage( image, 0, 0, this.width, this.height );
constructor ( image?: HTMLImageElement, canvas?: HTMLCanvasElement ) {
if ( image ) {
this.canvas = document.createElement( 'canvas' );
this.context = this.canvas.getContext( '2d' );
this.width = this.canvas.width = image.naturalWidth;
this.height = this.canvas.height = image.naturalHeight;
this.context.drawImage( image, 0, 0, this.width, this.height );
} else if ( canvas ) {
this.canvas = canvas;
this.context = this.canvas.getContext( '2d' );
this.width = this.canvas.width;
this.height = this.canvas.height;
} else {
throw new Error("One of the two constructor arguments needed");
}
}
getImageData = function () {