CANVAS | SVG |
|
|
Property | Description |
fillStyle | Syntax: context.fillStyle=color|gradient|pattern; Specifies or returns the color, gradient, or pattern used to fill the drawing. |
strokeStyle | Syntax: context.strokeStyle=color|gradient|pattern; Specifies or returns the color, gradient, or pattern used for strokes. |
shadowColor | Syntax: context.shadowColor=color; Specifies or returns the color to use for shadows. |
shadowBlur | Syntax: context.shadowBlur=number; Specifies or returns the blur level for shadows |
shadowOffsetX | Syntax: context.shadowOffsetX=number; Specifies or returns the horizontal distance in pixels of the shadow from the shape. |
shadowOffsetY | Syntax: context.shadowOffsetY=number; Specifies or returns the vertical distance in pixels of the shadow from the shape. |
Method | Description |
createLinearGradient() | Syntax: context.createLinearGradient=(x0,y0,x1,y1); Creates a linear gradient (to use on canvas content). x0,y0,x1,y1 are the start and endpoints for the gradient, in pixels. |
createPattern() | Syntax: context.createPattern=(image,"repeat|repeat-x|repeat-y|no-repeat"); Repeats a specified element in the specified direction. |
createRadialGradient() | Syntax: context.createRadialGradient=(x0,y0,r0,x1,y1,r1); Creates a radial/circular gradient (to use on canvas content). |
addColorStop() | Syntax: context.addColorStop=(stop,color); Specifies the colors and stop positions in a gradient object. stop is a value between 0.0 and 1.0. |
Property | Description |
lineCap | Syntax: context.lineCap=butt|round|square; Specifies or returns the style of the end caps for a line. |
lineJoin | Syntax: context.lineJoin=bevel|round|miter; Specifies or returns the type of corner created, when two lines meet. |
lineWidth | Syntax: context.lineWidth=number; Specifies or returns the current line width in pixels. |
miterLimit | Syntax: context.miterLimit=number; Specifies or returns the maximum miter length. Note that if the miter length exceeds the specified maximum miter length, the lineJoin will be displayed as "bevel". |
Method | Description |
rect() | Syntax: context.rect=(x,y,width,height); Creates a rectangle. All values in pixels. |
fillRect() | Syntax: context.fillRect=(x,y,width,height); Draws a "filled" rectangle. All values in pixels. |
strokeRect() | Syntax: context.strokeRect=(x,y,width,height); Draws a rectangle (no fill). All values in pixels. |
clearRect() | Syntax: context.clearRect=(x,y,width,height); Clears the specified pixels within a given rectangle, i.e. a white rectangle in the outer rectangle. All values in pixels. |
Method | Description |
fill() | Syntax: context.fill=(); Fills the current drawing (path) according to the specified parameters e.g. fillStyle(). |
stroke() | Syntax: context.stroke=(); Actually draws the path you have defined, e.g. using lineTo() and moveTo(). beginPath=() starts the description and stroke=() ends the description. |
beginPath() | Syntax: context.beginPath=(); Begins a path, or resets the current path you have defined, e.g. using lineTo() and moveTo(). beginPath=() starts the description and stroke=() ends the description. |
moveTo() | Syntax: context.moveTo=(x,y); Moves the path to the specified point in the canvas, without creating a line. Coordinates are i pixels. |
closePath() | Syntax: context.closePath=(); Creates a path from the current point back to the starting point. |
lineTo() | Syntax: context.lineTo=(x,y); Adds a new point and creates a line to that point from the last specified point in the canvas. |
clip() | Syntax: context.clip=(); Clips a region of any shape and size from the original canvas. |
quadraticCurveTo() | Syntax: context.quadraticCurveTo=(cpx,cpy,x,y); Creates a quadratic Bézier curve. Coordinates are i pixels. |
bezierCurveTo() | Syntax: context.bezierCurveTo=(cp1x,cp1y,cp2x,cp2y,x,y); Creates a cubic Bézier curve. Coordinates are i pixels. |
arc() | Syntax: context.arc=(x,y,r,sAngle,eAngle,counterclockwise); Creates an arc/curve (i.e. circles, or parts of circles). |
arcTo() | Syntax: context.arcTo=(x1,y1,x2,y2,r); Creates an arc/curve between two tangents. |
isPointInPath() | Syntax: context.isPointInPath=(x,y); Testing for whether the specified coordinate is on the specified path. |
Method | Description |
scale() | Syntax: context.scale=(scalewidth,scaleheight); Scales the current drawing bigger or smaller. |
rotate() | Syntax: context.rotate=(angle); Rotates the current drawing. |
translate() | Syntax: context.translate=(x,y); Remaps the (0,0) position on the canvas to the (x,y) coordinates. Coordinates in pixels. |
transform() | Syntax: context.transform=(a,b,c,d,e,f); Replaces the current transformation matrix for the drawing. |
setTransform() | Syntax: context.setTransform=(a,b,c,d,e,f); Resets the current transform to the identity matrix. Then runs transform(). |
Property | Description |
font | Syntax: context.font=font-style| font-variant| font-weight| font-size/line-height| font-family| caption| icon| menu| message-box| small-caption| status-bar; Specifies or returns the current font properties for text content. |
textAlign | Syntax: context.textAlign=center|end|left|right|start; Specifies or returns the current alignment for text content. |
textBaseline | Syntax: context.textBaseline=alphabetic|top|hanging|middle|ideographic|bottom; Specifies or returns the current text baseline used when drawing text. |
Method | Description |
fillText() | Syntax: context.fillText=(text,x,y,maxWidth); Draws "filled" text, i.e. not outlined text, on the canvas. |
strokeText() | Syntax: context.strokeText=(text,x,y,maxWidth); Draws outlined text on the canvas. |
measureText() | Syntax: context.measureText=(text).width; Returns an object that contains the width of the specified text. |
Method | Description |
drawImage() | Syntax: context.drawImage=(img,sx,sy,swidth,sheight,x,y,width,height); Draws an image, canvas, or video onto the canvas. |
Property | Description |
width | Syntax: imgData.width; Returns the width of an ImageData object. |
height | Syntax: imgData.height; Returns the height of an ImageData object. |
data | Syntax: imgData.data; Returns an object that contains image data of a specified ImageData object. |
Method | Description |
createImageData() | Syntax: context.createImageData=(width,height) or context.createImageData=(imageData); Creates a new, blank ImageData object. |
getImageData() | Syntax: context.getImageData=(x,y,width,height); Returns an ImageData object that copies the pixel data for the specified rectangle on a canvas. |
putImageData() | Syntax: context.putImageData=(imgData,x,y,dirtyX,dirtyY,dirtyWidth,dirtyHeight); Puts the image data (from a specified ImageData object) back onto the canvas. |
Property | Description |
globalAlpha | Syntax: context.globalAlpha=number; Specifies or returns the current alpha or transparency value of the drawing. The transparency value must be a number between 0.0 (fully transparent) and 1.0 (no transparancy) |
globalCompositeOperation | Syntax: context.globalCompositeOperation=source-over| source-atop| source-in| source-out| destination-over| destination-atop| destination-in| destination-out| lighter| copy| xor; Specifies or returns how a new image are drawn onto an existing image. |
Method | Description |
save() | Syntax: context.save(); Saves the state of the current context. |
restore() | Syntax: context.restore(); Returns previously saved path state and attributes. |
createEvent() | Syntax: context.createEvent=(type); Creates an event of the specified type. Please note that many methods used with createEvent, are deprecated. Use event constructors instead. |
getContext() | Syntax: context.getContext=(2d|webgl|webgl2|bitmaprenderer, contextAttributes); Returns a drawing context on the canvas, or null if the context identifier is not supported. |
toDataURL() | Syntax: context.toDataURL=(type, encoderOptions); Returns a data URI containing a representation of the image in the format specified by the type parameter (PNG is default). i.e. it converts the CANVAS image to .png or .jpg, depending on specification. The returned image is in a 96 dpi resolution. |