-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
82 lines (76 loc) · 2.59 KB
/
index.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="favicon.png">
<title>Celebrate Pride</title>
<link rel="stylesheet" href="buttons-min.css">
</head>
<style>
.is-center {
text-align: center;
margin: auto;
width: 100%;
}
</style>
<body bgcolor="#F8BBD0">
<div class="is-center" id="container">
<canvas id="canvas" style="display:none"></canvas>
<h1>Celebrate Pride!</h1>
<input type="file" id = "upload-input" style="display: none;">
<button id="upload-btn" style="margin-top:20%;" class="pure-button pure-button-primary">Upload a photo</button>
</div>
</body>
<script src="jquery-1.11.3.min.js"></script>
<script>
var canvas = $('#canvas');
var imgurID = window.location.href.split('#')[1];
if(imgurID != null){
$("#upload-btn").hide();
var img = new Image();
img.setAttribute('crossOrigin', 'anonymous');
img.onload = imgOnLoad;
img.src = "http://i.imgur.com/"+imgurID+".png";
}
$( "#upload-btn" ).on( "click", function() { $("#upload-input").click(); });
$('#upload-input').change(function(e) {
var file = e.target.files[0],
imageType = /image.*/;
if (!file.type.match(imageType))
return;
var reader = new FileReader();
reader.onload = fileOnload;
reader.readAsDataURL(file);
});
function imgOnLoad(){
$("#upload-btn").hide();
var res = this.height/this.width;
var scale = Math.min.apply(Math, [$(window).width(), $(window).height(), this.height, this.width]);
var width = canvas[0].width = scale;
var height = canvas[0].height = scale*res;
var context = canvas[0].getContext('2d');
context.drawImage(this, 0, 0,width,height);
context.fillStyle = 'rgba(255,0,0,0.4)';
context.fillRect(0,0,width,height*0.167);
context.fillStyle = 'rgba(255,153,0,0.5)';
context.fillRect(0,height*0.167,width,height*0.167*2);
context.fillStyle = 'rgba(255,255,0,0.3)';
context.fillRect(0,height*0.167*2,width,height*0.167*3);
context.fillStyle = 'rgba(0,153,0,0.3)';
context.fillRect(0,height*0.167*3,width,height*0.167*4);
context.fillStyle = 'rgba(0,0,255,0.3)';
context.fillRect(0,height*0.167*4,width,height*0.167*5);
context.fillStyle = 'rgba(204,0,153,0.3)';
context.fillRect(0,height*0.167*5,width,height*0.167*6);
var img = new Image();
img.src = canvas[0].toDataURL();
$("#container").append(img);
}
function fileOnload(e) {
var img = new Image();
img.onload = imgOnLoad;
img.src = e.target.result;
}
</script>
</html>