-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagePercentTool_canvas.html
101 lines (77 loc) · 1.98 KB
/
imagePercentTool_canvas.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<meta charset=utf-8 />
<title></title>
<style type="text/css">
#blah{
border:1px solid black;
visibility: hidden;
}
#space{
height:100px;
}
#text{
border:1px solid black;
width: 200px;
height: 30px;
text-align:center;
display: table-cell;
vertical-align: middle;
}
</style>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
make_base();
function make_base()
{
base_image = new Image();
base_image.src = e.target.result;
base_image.onload = function(){
canvas.width = base_image.width;
canvas.height = base_image.height;
context.drawImage(base_image, 0, 0 );
}
}
};
reader.readAsDataURL(input.files[0]);
}}
$( document ).ready(function() {
$("#canvas").click(function(e){
getPosition(e);
});
var pointSize = 3;
function getPosition(event){
var rect = canvas.getBoundingClientRect();
var x = event.clientX - rect.left;
var y = event.clientY - rect.top;
var xp = ((1-((rect.right - event.clientX)/canvas.width))).toFixed(3)
var yp = ((((event.clientY - rect.top)/canvas.height))).toFixed(3)
$('#pp').append("<p>"+xp+""+" "+yp+"</p>")
drawCoordinates(x,y);
}
function drawCoordinates(x,y){
var ctx = document.getElementById("canvas").getContext("2d");
ctx.fillStyle = "#ff2626"; // Red color
ctx.beginPath();
ctx.arc(x, y, pointSize, 0, Math.PI * 2, true);
ctx.fill();
}
});
</script>
</head>
<body>
<input type='file' onchange="readURL(this);" />
<div id="space"></div>
<canvas id="canvas" width="690" height="651">
</canvas>
<div id="space"></div>
<div id="pp">Your coordinates are:</div>
</body>
</html>