-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
248 lines (222 loc) · 6.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<html lang="en">
<head>
<meta charset="utf-8" />
<title>This Person Exists</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="This Person Exists" />
<style>
body {
-webkit-transition: 3s -webkit-filter linear;
-moz-transition: 3s -moz-filter linear;
-moz-transition: 3s filter linear;
-ms-transition: 3s -ms-filter linear;
-o-transition: 3s -o-filter linear;
transition: 3s filter linear, 3s -webkit-filter linear;
filter: grayscale(0);
}
body,
html {
display: flex;
justify-content: center;
align-items: center;
background-color: #000;
margin: 0;
padding: 0;
width: 100%;
height: 100%;
position: relative;
font-family: Arial;
font-size: 0.9em;
overflow-x: hidden;
transition: background-color 0.5s ease;
}
#description {
box-sizing: border-box;
position: absolute;
background-color: #fff;
border: 1px solid #ccc;
transition: all 0.5s ease 0s;
padding: 5px 8px;
bottom: 5px;
opacity: 0;
right: -500px;
}
#description p {
padding: 0;
margin: 0;
}
#description.show {
opacity: 0.7;
right: 5px;
}
#description.show:hover {
opacity: 1;
}
#description a {
color: #00f;
cursor: pointer;
}
#description a:hover {
text-decoration: underline;
}
@media only screen and (max-width: 600px) {
#description {
width: 100%;
font-size: 0.8em;
padding: 5px 15px;
}
}
#face {
max-width: 100%;
max-height: 100%;
text-align: center;
}
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.close {
position: absolute;
right: 10px;
bottom: 1px;
width: 16px;
height: 16px;
opacity: 0.3;
}
.close:hover {
opacity: 1;
}
.close:after,
.close:before {
position: absolute;
left: 15px;
content: " ";
height: 13px;
width: 2px;
background-color: #333;
}
.close:before {
transform: rotate(45deg);
}
.close:after {
transform: rotate(-45deg);
}
#another {
padding: 6px 0;
display: inline-block;
font-size: 1.2em;
}
</style>
</head>
<body>
<canvas id="face"></canvas>
<div id="description">
<p>
These humans exist. They have been used to train <br />
Nvidia's <a href="https://github.com/NVlabs/stylegan">StyleGan</a> and
serve as the raw
<br />
material of
<a href="https://thispersondoesnotexist.com"
>thispersondoesnotexist.com</a
>.
</p>
<p>
This <a href="#" id="linkback">particular photo</a> was taken by<br />
<span id="author"></span>.
</p>
<p>It is released under a Creative Commons license.</p>
<p>
<a href="mailto:[email protected]">Contact me</a> or view the
<a href="https://github.com/vincentwoo/thispersonexists">source code</a>
for this website.
</p>
<p>
<a id="another" title="Request another photo">Another</a>
<a id="close" class="close"></a>
</p>
</div>
<script type="text/javascript">
var canvas = document.getElementById("face");
var ctx = canvas.getContext("2d");
function preloadFace() {
var faceId = Math.floor(Math.random() * Math.floor(65212));
return fetch("data/" + faceId + ".json").then(function(response) {
return response.json()
}).then(function(response) {
response.image = new Image()
response.image.src = response.photo_url
return new Promise(function(resolve) {
response.image.onload = function() { resolve(response) }
response.image.onerror = function() { resolve(preloadFace()) }
})
})
}
function renderFace(response) {
const image = response.image
document.getElementById("author").textContent = response.author;
document.getElementById("linkback").href = response.flickr_url;
var quad = response.face_quad;
var center = quad.reduce(
function(center, pt) {
center[0] += pt[0] / 4;
center[1] += pt[1] / 4;
return center;
},
[0, 0]
);
var theta = Math.atan2(
quad[3][1] - quad[0][1],
quad[3][0] - quad[0][0]
);
var bufferCanvas = document.createElement("canvas");
var bufferCtx = bufferCanvas.getContext("2d");
bufferCtx.canvas.width = image.width;
bufferCtx.canvas.height = image.height;
bufferCtx.save();
bufferCtx.translate(center[0], center[1]);
bufferCtx.rotate(-theta);
bufferCtx.translate(-center[0], -center[1]);
var matrix = bufferCtx.getTransform();
bufferCtx.beginPath();
bufferCtx.moveTo(quad[0][0], quad[0][1]);
bufferCtx.lineTo(quad[1][0], quad[1][1]);
bufferCtx.lineTo(quad[2][0], quad[2][1]);
bufferCtx.lineTo(quad[3][0], quad[3][1]);
bufferCtx.clip();
bufferCtx.drawImage(image, 0, 0);
quad = quad.map(function(pt) {
return transformPoint(pt, matrix);
});
var x = quad[0][0];
var y = quad[0][1];
var side = Math.floor(quad[2][0] - x);
ctx.canvas.width = side;
ctx.canvas.height = side;
ctx.drawImage(bufferCanvas, x, y, side, side, 0, 0, side, side);
}
function transformPoint(point, matrix) {
return [
matrix.a * point[0] + matrix.c * point[1] + matrix.e,
matrix.b * point[0] + matrix.d * point[1] + matrix.f,
];
}
preloadFace().then(function(response) { renderFace(response) });
let bufferedFace = preloadFace()
document.getElementById("another").onclick = function() {
bufferedFace.then(function(response) {
renderFace(response)
bufferedFace = preloadFace()
})
}
document.getElementById("close").onclick = function() {
document.getElementById("description").className = "";
};
setTimeout(function() {
document.getElementById("description").className = "show";
}, 3000);
</script>
</body>
</html>