-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathstache3.html
42 lines (38 loc) · 1.25 KB
/
stache3.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
<html>
<head>
<title>Canvas example</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
var canvas = $('#sandbox')[0], // a.k.a. document.getElementById('sandbox');
ctx = canvas.getContext('2d'),
faceLoaded = false,
stacheLoaded = false,
face, stache;
function draw(){
ctx.drawImage(face, 0, 0);
var stacheAspect = stache.width / stache.height;
var newStacheHeight = 50;
ctx.drawImage(stache, 75, 255, stacheAspect * newStacheHeight, newStacheHeight);
}
face = new Image();
face.onload = function(){
faceLoaded = true;
if (stacheLoaded) draw();
};
face.src = 'http://www.librarising.com/astrology/celebs/images2/QR/queenelizabethii.jpg';
stache = new Image();
stache.onload = function(){
stacheLoaded = true;
if (faceLoaded) draw();
};
stache.src = 'http://mustachify.me/images/staches/mustache_03.png';
});
</script>
</head>
<body>
<canvas id="sandbox" width="400" height="400">
Sorry, get a better browser.
</canvas>
</body>
</html>