ImageCanvas

Usefull class for working with JS canvas object.

Constructor

new ImageCanvas(widthopt, heightopt)

Parameters:
NameTypeAttributesDescription
widthnumber<optional>

Canvas width. Default 256.

heightnumber<optional>

Canvas height. Default 256.

Methods

drawImage(img, xopt, yopt, widthopt, heightopt)

Draw an image on the canvas.

Parameters:
NameTypeAttributesDescription
imgImage

Draw image.

xnumber<optional>

Left top image corner X coordinate on the canvas.

ynumber<optional>

Left top image corner Y coordinate on the canvas.

widthnumber<optional>

Image width slice. Image width is default.

heightnumber<optional>

Image height slice. Image height is default.

drawText(text, xopt, yopt, fontopt, coloropt)

Draw a text on the canvas.

Parameters:
NameTypeAttributesDefaultDescription
textstring

Text.

xnumber<optional>
0

Canvas X - coordinate. 0 - default.

ynumber<optional>
14

Canvas Y - coordinate. 0 - default.

fontstring<optional>
normal 14px Verdana

Font style. 'normal 14px Verdana' - is default.

colorstring<optional>
black

Css font color.

fill(color)

Fills canvas RGBA with color.

Parameters:
NameTypeDescription
colorstring

CSS string color.

fillColor(color)

Fill the canvas by color.

Parameters:
NameTypeDescription
colorstring

CSS string color.

fillEmpty()

Fills canvas RGBA with zeroes.

getCanvas() → {HTMLCanvasElement}

Returns canvas object.

Returns:
Type: 
HTMLCanvasElement

getContext() → {CanvasRenderingContext2D}

Returns canvas context pointer.

Returns:
Type: 
CanvasRenderingContext2D

getData() → {Uint8ClampedArray}

Gets canvas pixels RGBA data.

Returns:
Type: 
Uint8ClampedArray

getHeight() → {number}

Gets canvas height.

Returns:
Type: 
number

getImage() → {Image}

Converts canvas to JS image object.

Returns:
Type: 
Image

getTextWidth(text) → {number}

Get measured text width.

Parameters:
NameTypeDescription
textstring

Measured text.

Returns:
Type: 
number

getWidth() → {number}

Gets canvas width.

Returns:
Type: 
number

load(url, callbackopt)

Load image to canvas.

Parameters:
NameTypeAttributesDescription
urlstring

Image url.

callbackfunction<optional>

Image onload callback.

openImage()

Open canvas image in the new window.

resize(width, height)

Resize canvas.

Parameters:
NameTypeDescription
widthnumber

Width.

heightnumber

Height.

setData(data)

Sets RGBA pixel data.

Parameters:
NameTypeDescription
dataArray.<number>

Array RGBA data.