CanvasUtils

CanvasUtils

Provides useful canvas-related methods

Constructor

new CanvasUtils()

Methods

(static) getMatrixFromCanvas(canvas) → {Array}

Takes a canvas element and returns it's image data as a matrix.
Useful for things such as heightmap displacement from image source.

Parameters:
Name Type Description
canvas

(static) loadCanvasFromPath(canvasPath, callback)

Loads an image element from a given URL and returns the image rendered on a canvas within a callback.

Parameters:
Name Type Description
canvasPath string

The URL to the image to render to the canvas.

callback function

(static) renderSvgToCanvas(svgSource, options, callback)

Renders an SVG to a canvas element.

Parameters:
Name Type Description
svgSource string

The SVG XML source code

options Object

Will be passed to loadCanvasFromPath.

callback function

Will be called when done. The single argument to this function will be the HTMLCanvasElement, or null if an error occurred.

Example
var data = '<svg xmlns="http://www.w3.org/2000/svg" width=100 height=100><rect x=0 y=0 width=100 height=100 fill="blue" /></svg>';
CanvasUtils.renderSvgToCanvas(data, {
    resizeToFit:true,
    width:100,
    height:100
}, function (canvas) {
    // canvas is an HTMLCanvasElement
});

(static) svgDataToImage(data) → {Promise}

Convert SVG XML content to an HTMLImageElement.

Parameters:
Name Type Description
data string