Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Created December 29, 2013 16:38
Show Gist options
  • Save seansullivan/8172122 to your computer and use it in GitHub Desktop.
Save seansullivan/8172122 to your computer and use it in GitHub Desktop.
Load image into canvas
<canvas id="canvas"></canvas>
<script type="text/javascript">
var can = document.getElementById('canvas');
var ctx = can.getContext('2d');
var img = new Image();
img.onload = function(){
can.width = img.width;
can.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
}
img.src = 'test.jpg';
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment