<!DOCTYPE html>
<html>
<head>
<title>javascript test</title>
<meta charset="UTF-8">
<style>
</style>
</head>
<body style="margin:0;padding:0;position:relative;">
<form>
<canvas id="canvas" onclick="showCoords() " style="cursor: crosshair;border:1px solid" >
</canvas></br>
<input type="file" id="inp">
<input type="button" value="Clear Sketchpad" id="clearbutton" onclick="clearCanvas()">
</form>
<script>
/////////////////////////////////////////////////////////////////////////////////////////////
document.getElementById('inp').onchange = function(e) {
var img = new Image();
img.onload = draw;
img.onerror = failed;
img.src = URL.createObjectURL(this.files[0]);
};
function draw() {
const canvas = document.getElementById('canvas');
canvas.width = this.width;
canvas.height = this.height;
const ctx = canvas.getContext('2d');
ctx.drawImage(this, 0,0);
}
/////////////////////////////////////////////////////////////////////////////////////////////
var ctx2 = canvas.getContext('2d');
function showCoords() {
var x = event.clientX;
var y = event.clientY;
ctx2.beginPath();
ctx2.arc(x,y,5,0,2*Math.PI);
ctx2.fill();
ctx2.stroke();
}
function clearCanvas(){
ctx2.clearRect(0, 0, canvas.width, canvas.height);
}
function failed() {
console.error("ERROR");
}
</script>
</body>
</html>