Skip to content

Instantly share code, notes, and snippets.

@jrm2k6
Created March 19, 2014 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrm2k6/5ca5c121360444372db4 to your computer and use it in GitHub Desktop.
Save jrm2k6/5ca5c121360444372db4 to your computer and use it in GitHub Desktop.
<html>
<body>
<canvas id="myCanvas" width="1000" height="1000" style="border: 3px solid red;">
</canvas>
<script>
var canvas = document.getElementById('myCanvas');
var ok = 1;
try {
var ctx = canvas.getContext("2d");
} catch (err) {
ok = 0;
}
if (ok == 1) {
// defining mask
ctx.fillStyle = 'red';
ctx.fillRect(100, 100, 200, 300);
ctx.clip();
base_image = new Image();
base_image.src = 'jeremy_cropping.png';
base_image.width = 50;
base_image.height = 50;
base_image.onload = function () {
ctx.drawImage(base_image, 0, 0, 50, 50);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment