Files
JavaScript-from-Beginner-to…/Chapter 14/Code Samples/ch14-drawing-image.html
T
2022-01-03 17:27:58 +05:30

24 lines
638 B
HTML
Executable File

<html>
<head>
<style>
canvas {
border: 1px solid black;
}
</style>
</head>
<body>
<canvas id="c1"></canvas>
<img id="flower" src="flower.jpg" />
<script>
window.onload = function () {
let canvas = document.getElementById("c1");
canvas.height = 300;
canvas.width = 300;
let ctx = canvas.getContext("2d");
let myImage = document.getElementById("flower"); //This line adds the image on the canvas, you can hide the <img> tag by " style="display: none;" "
ctx.drawImage(myImage, 10, 10);
};
</script>
</body>
</html>