canvas
Small helpers for creating a canvas element and drawing to its 2D context.
Import: @rtorcato/browser-common/canvas
Example
import {
createCanvas,
fillCanvas,
drawImageOnCanvas,
canvasToDataURL,
} from '@rtorcato/browser-common/canvas'
const canvas = createCanvas(640, 480)
document.body.append(canvas)
fillCanvas(canvas, '#fafafa')
drawImageOnCanvas(canvas, image, 10, 20)
const png = canvasToDataURL(canvas)
Exports
createCanvas(width, height)— creates anHTMLCanvasElementgetCanvasContext2D(canvas)— returns the 2D rendering context, ornullclearCanvas(canvas)— clears the entire canvasdrawImageOnCanvas(canvas, image, dx, dy)— draws an image onto the canvascanvasToDataURL(canvas, type?, quality?)— converts canvas content to a data URLfillCanvas(canvas, color)— fills the entire canvas with a color
See the API reference for full signatures.