Skip to content

Instantly share code, notes, and snippets.

@john92paul
Last active January 20, 2020 13:36
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 john92paul/a75a3df1457c39eefc9e103c996045ac to your computer and use it in GitHub Desktop.
Save john92paul/a75a3df1457c39eefc9e103c996045ac to your computer and use it in GitHub Desktop.
<!-- HTML -->
<html>
<body>
<canvas id="myCanvas" width="750" height="500">your canvas loads here</canvas>
</body>
</html>
<!-- Javascript -->
<script>
var myCanvas = document.getElementById("myCanvas");
var myContext = myCanvas.getContext("2d");
myCanvas.width="750"; // Optional
myCanvas.height="500"; // Optional
var myImage=new Image();
myImage.src="https://images.unsplash.com/photo-1572800578930-fd1013b506c1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=750&q=80";
myImage.onload=function(){
myContext.drawImage(myImage,0,0,myCanvas.width,myCanvas.height);
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment