context.clip
Limits any future drawings to display only inside the current Path.
Example: Clip this image into a triangular Path
<!doctype html>
<html>
<head>
<style>
body{ background-color:white; }
#canvas{border:1px solid red; }
</style>
<script>
window.onload=(function(){
// canvas related variables
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
var img=new Image();
img.onload=start;
img.src='http://i.stack.imgur.com/1CqWf.jpg'
function start(){
// draw a triangle path
ctx.beginPath();
ctx.moveTo(75,50);
ctx.lineTo(125,100);
ctx.lineTo(25,100);
ctx.lineTo(75,50);
// clip future drawings to appear only in the triangle
ctx.clip();
// draw an image
ctx.drawImage(img,0,0);
}
}); // end window.onload
</script>
</head>
<body>
<canvas id="canvas" width=150 height=150></canvas>
</body>
</html>