-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathexample.html
70 lines (67 loc) · 1.87 KB
/
example.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
<!DOCTYPE html>
<html>
<head>
<title>Focus</title>
<style>
body {
padding: 50px;
font: 14px Helvetica, Arial, sans-serif;
}
input[type='text'] {
padding: 5px;
width: 300px;
}
canvas {
float: left;
clear: both;
}
#thumb {
float: left;
clear: both;
overflow: hidden;
border: 1px dotted #ddd;
}
</style>
</head>
<body>
<h1>Focus</h1>
<p>Focal point detection algorithm. Drag and drop an image! <span id="point"></span></p>
<canvas id="source"></canvas>
<canvas id="thumb" width=300 height=300></canvas>
<script src="build/build.js"></script>
<script>
var point = document.querySelector('#point');
var focus = require('focus');
var Dropload = require('component-dropload');
var File = require('component-file');
var canvas = document.querySelector('#source');
var ctx = canvas.getContext('2d');
var drop = Dropload(document.querySelector('html'));
drop.on('upload', function(upload){
var file = File(upload.file);
file.toDataURL(function(err, str){
var img = new Image;
img.onload = function(){
var w = img.width;
var h = img.height;
canvas.width = w;
canvas.height = h;
ctx.drawImage(img, 0, 0);
var p = focus(canvas, { debug: true });
point.textContent = p.toString();
thumb(img, p);
};
img.src = str;
});
});
function thumb(img, p) {
var canvas = document.querySelector('#thumb');
var ctx = canvas.getContext('2d');
var w = canvas.width;
var h = canvas.height;
ctx.clearRect(0, 0, w, h);
ctx.drawImage(img, -(p.x - w / 2), -(p.y - h / 2));
}
</script>
</body>
</html>