canvasGenerator.ts 719 B

12345678910111213141516171819202122
  1. /**
  2. * Helper class used to generate a canvas to manipulate images
  3. */
  4. export class CanvasGenerator {
  5. /**
  6. * Create a new canvas (or offscreen canvas depending on the context)
  7. * @param width defines the expected width
  8. * @param height defines the expected height
  9. * @return a new canvas or offscreen canvas
  10. */
  11. public static CreateCanvas(width: number, height: number): HTMLCanvasElement | OffscreenCanvas {
  12. if (typeof document === "undefined") {
  13. return new OffscreenCanvas(width, height);
  14. }
  15. let canvas = document.createElement("canvas");
  16. canvas.width = width;
  17. canvas.height = height;
  18. return canvas;
  19. }
  20. }