Class: ImageCanvas

og.ImageCanvas

new og.ImageCanvas(width, height)

Usefull class for working with JS canvas object.
Name Type Description
width number optional Canvas width. Default 256.
height number optional Canvas height. Default 256.

Members

protected_canvasObject

Canvas object.

protected_contextObject

Canvas context.

Methods

drawImage(img, x, y, width, height)

Draw an image on the canvas.
Name Type Description
img Image Draw image.
x number optional Left top image corner X coordinate on the canvas.
y number optional Left top image corner Y coordinate on the canvas.
width number optional Image width slice. Image width is default.
height number optional Image height slice. Image height is default.

drawText(text, x, y, font, color)

Draw a text on the canvas.
Name Type Description
text string Text.
x number optional Canvas X - coordinate. 0 - default.
y number optional Canvas Y - coordinate. 0 - default.
font string optional Font style. 'normal 14px Verdana' - is default.
color string optional Css font color.
Fill the canvas by color.
Name Type Description
color string CSS string color.
Fills canvas RGBA with zeroes.
Returns canvas object.
Returns:
Type Description
Object
Returns canvas context pointer.
Returns:
Type Description
Object

getData(){Array.<number>}

Gets canvas pixels RGBA data.
Returns:
Type Description
Array.<number>
Gets canvas height.
Returns:
Type Description
number
Converts canvas to JS image object.
Returns:
Type Description
Image

getTextWidth(text){number}

Get measured text width.
Name Type Description
text string Measured text.
Returns:
Type Description
number
Gets canvas width.
Returns:
Type Description
number
Load image to canvas.
Name Type Description
url string Image url.
Open canvas image in the new window.

resize(width, height)

Resize canvas.
Name Type Description
width number Width.
height number Height.
Sets RGBA pixel data.
Name Type Description
data Array.<number> Array RGBA data.