-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
705 lines (626 loc) · 19 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
<!DOCTYPE html>
<html>
<head>
<title>웹캠 좌우 반전</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&display=swap"
rel="stylesheet"
/>
<script
async
src="https://docs.opencv.org/3.4.0/opencv.js"
onload="onOpenCvReady();"
type="text/javascript"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.4.1/html2canvas.min.js"
integrity="sha512-BNaRQnYJYiPSqHHDb58B0yaPfCu+Wgds8Gp/gU33kqBtgNS4tSPHuGibyoeqMV/TJlSKda6FXzoEyYGjTe+vXA=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<style>
body {
background-color: black;
}
.container {
padding: 40px;
}
.center {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#videoElement {
width: 800px;
height: 600px;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scaleX(-1);
}
#title {
color: white;
font-family: "DM Serif Display", serif;
text-shadow: 1px 1px 0px rgba(220, 220, 220, 0.5);
letter-spacing: 4px;
position: fixed;
top: 20px;
left: 100px;
}
#captureButton {
width: 80px;
height: 80px;
border-radius: 50%;
background-color: #fff;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
display: flex;
justify-content: center;
align-items: center;
position: fixed;
bottom: 20px;
left: calc(50% - 40px);
z-index: 999;
}
#captureButton:before {
content: "";
width: 64px;
height: 64px;
border-radius: 50%;
background-color: #ccc;
}
#captureButton:active:before {
background-color: #ddd;
}
#captureButton:active {
transform: scale(0.95);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
#photoList {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: minmax(100px, auto);
gap: 10px;
list-style: none;
padding: 0;
}
#photoList > li {
padding: 10px;
text-align: center;
}
#selectPhotoList {
display: grid;
grid-template-columns: repeat(1, 1fr);
grid-auto-rows: minmax(100px, auto);
gap: 40px;
list-style: none;
padding: 0;
}
#selectPhotoList > li {
padding: 10px;
text-align: center;
}
#remainingCount {
text-align: center;
margin-top: 10px;
margin-left: 10px;
font-weight: bold;
color: white;
}
#countdownTimer {
color: white;
}
#photo-choice-section {
display: flex;
justify-content: space-around;
align-items: center;
width: 90%;
}
#photoList {
/* border: solid salmon 2px; */
width: 840px;
}
#photoList > li {
/* border: solid white 2px; */
width: 240px;
height: 180px;
}
#photoList > li.selected {
box-shadow: 0 0 0 3px rgb(255, 255, 255) inset;
}
#selectPhotoList {
/* border: solid salmon 2px; */
width: 260px;
height: 800px;
}
#selectPhotoList > li {
/* border: solid white 2px; */
width: 260px;
height: 196px;
}
#selectPhotoList > li > img {
/* border: solid white 2px; */
width: 100%;
height: 100%;
}
.frame {
position: relative;
width: 300px;
height: 900px;
}
.frame-img {
position: relative;
z-index: 2;
width: 100%;
height: 100%;
}
.frame-hole {
position: absolute;
z-index : 1;
width: 260px;
height: 200px;
}
.selected-image {
position: absolute;
object-fit: cover;
width: 100%;
height: 100%;
}
.hole1 {
top: 65px;
left: 20px;
}
.hole2 {
top: 270px;
left: 20px;
}
.hole3 {
top: 475px;
left: 20px;
}
.hole4 {
top: 680px;
left: 20px;
}
#description-section {
position: fixed;
top: 40%;
left: 50%;
transform: translate(-50%, -50%);
}
.desc {
color: white;
}
#startIcon {
width: 50%;
height: 80%;
}
#startButton {
position: absolute;
top: 100%;
left: 50%;
transform: translate(-50%, -50%);
width: 500px;
height: 300px;
background-color: white;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
transition: 0.3s ease;
border: 8px solid black;
border-radius: 60px;
}
#startButton:hover {
transition: 0.3s ease;
filter: invert(100%);
}
.check-btn {
width: 200px;
height: 200px;
background-color: white;
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
transition: 0.3s ease;
border: 8px solid black;
border-radius: 200px;
}
.check-btn:hover {
transition: 0.3s ease;
filter: invert(100%);
}
.check-btn > img {
width: 80%;
height: 80%;
}
#photo-output-section {
margin-top: 40px;
display: flex;
justify-content: space-around;
align-items: center;
width: 80%;
}
#select-frame-section {
background-color: rgb(0, 0, 0);
/* border: 6px solid rgb(255, 255, 255); */
/* border-radius: 20px; */
width: 50vw;
height: 70vh;
margin-right: 80px;
place-items : center;
display: grid;
grid-template-columns: repeat(6, 1fr);
grid-auto-rows: minmax(100px, auto);
gap: 10px;
}
.select-frame-item {
width: 100px;
height: 100px;
background-color: rgb(0, 0, 0);
border: 4px solid rgb(255, 255, 255);
border-radius: 60px;
display : flex;
align-items: center;
justify-content: center;
}
.select-frame-item-name {
font-size : 1.2rem;
font-weight : 700;
color : white
}
.visibility-hidden {
visibility: hidden;
}
#memorism-photo {
display: flex;
justify-content: center;
align-items: center;
}
#countdownTimer {
position :fixed;
top: 5%;
transform: translateY(-50%);
left: 50%;
transform: translateX(-50%);
z-index: 1;
font-size : 6rem;
font-weight : 600;
color : white;
}
</style>
</head>
<body>
<div class="container">
<h1 id="title">Memorism</h1>
<div id="description-section" class="container">
<button id="startButton">
<img id="startIcon" src="image/camera-icon.png" alt="startPhoto" />
</button>
</div>
<!-- 사진 촬영 섹션 -->
<div id="photo-capture-section" class="container visibility-hidden">
<span id="remainingCount">남은 사진 촬영 횟수: 8회</span>
<span id="countdownTimer"></span>
<div>
<video id="videoElement" width="780" height="600" autoplay></video>
</div>
<div>
<button id="captureButton"></button>
</div>
</div>
<!-- 사진 선택 섹션 -->
<div id="photo-choice-section" class="container center visibility-hidden">
<!-- 촬영한 사진 목록 -->
<ul id="photoList"></ul>
<ul id="selectPhotoList">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<button id="selectCompleteButton" class="check-btn" disabled>
<img src="image/check-icon.png" alt="select complete button" />
</button>
</div>
<!-- 출력될 파일 섹션 -->
<div id="photo-output-section" class="container center visibility-hidden">
<!-- 프레임 선택하는 섹션 -->
<div id="select-frame-section" class="container"></div>
<!-- 다운받을 섹션 -->
<div id="memorism-photo">
<div class="frame">
<div class="frame-hole hole1"></div>
<div class="frame-hole hole2"></div>
<div class="frame-hole hole3"></div>
<div class="frame-hole hole4"></div>
<img id="frame-img1" class="frame-img" src="frame/memorism-only-black.png" alt="Frame Image" />
</div>
<div class="frame">
<div class="frame-hole hole1"></div>
<div class="frame-hole hole2"></div>
<div class="frame-hole hole3"></div>
<div class="frame-hole hole4"></div>
<img id="frame-img2" class="frame-img" src="frame/memorism-only-black.png" alt="Frame Image" />
</div>
</div>
<!-- 다운로드 버튼 -->
<button id="downloadButton" class="check-btn">
<img src="image/check-icon.png" alt="photo download button" />
</button>
</div>
</div>
<script>
const descriptionSectionEl = document.getElementById(
"description-section"
);
const startButtonEl = document.getElementById("startButton");
const downloadButtonEl = document.getElementById("downloadButton");
const videoElement = document.getElementById("videoElement");
const photoCaptureSectionEl = document.getElementById(
"photo-capture-section"
);
const photoChoiceSectionEl = document.getElementById(
"photo-choice-section"
);
const photoOutputSectionEl = document.getElementById(
"photo-output-section"
);
const captureButton = document.getElementById("captureButton");
const photoList = document.getElementById("photoList");
const selectPhotoList = document.getElementById("selectPhotoList");
const remainingCountElement = document.getElementById("remainingCount");
const countdownTimer = document.getElementById("countdownTimer");
const selectCompleteButtonEl = document.getElementById(
"selectCompleteButton"
);
const frameHoles = document.querySelectorAll(".frame-hole");
const frameArr = [
{
imgSrc : "frame/치이카와프레임.png",
name : "모몽가"
},
{
imgSrc : "frame/치이카와프레임2.png",
name : "치이카와"
},
{
imgSrc : "frame/잔망루피프레임.png",
name : "잔망루피"
}
];
const photoArr = []; // 촬영한 이미지 배열
const selectedPhotoArr = []; // 선택된 이미지 배열
const maxCount = 9; // 최대 촬영 횟수
let remainingCount = maxCount; // 현재 남은 촬영 횟수
const countdownDuration = 10; // 카운트다운 기간 (초)
let countdownIntervalId; // 카운트다운 인터벌 ID
let countdownTime = countdownDuration; // 현재 카운트다운 시간
// 남은 촬영 횟수 update
function updateRemainingCount() {
remainingCountElement.innerHTML = `남은 사진 촬영 횟수: ${remainingCount}회`;
}
// 10초 카운트 다운
function startCountdown() {
countdownTime = countdownDuration;
countdownTimer.textContent = countdownTime;
playAudio();
countdownIntervalId = setInterval(() => {
countdownTime--;
countdownTimer.textContent = countdownTime;
if (countdownTime <= 0) {
clearInterval(countdownIntervalId);
capturePhoto();
}
}, 1000);
}
const audio = new Audio("voice/jammin-countdown.mp3");
function playAudio() {
if (audio.paused) {
audio.play();
} else {
audio.currentTime = 0; // 현재 위치를 처음으로 설정
audio.play();
}
}
function stopAudio() {
audio.pause();
audio.currentTime = 0; // 현재 위치를 처음으로 설정
}
// 사진 촬영
function capturePhoto() {
clearInterval(countdownIntervalId); // 카운트다운 중지
const canvas = document.createElement("canvas");
canvas.width = videoElement.width;
canvas.height = videoElement.height;
const context = canvas.getContext("2d");
context.scale(-1, 1); // 이미지 좌우 반전 처리
context.drawImage(
videoElement,
-canvas.width,
0,
canvas.width,
canvas.height
);
// 개별 이미지 다운로드
// const link = document.createElement("a");
// link.href = canvas.toDataURL();
// link.download = "captured_image.png";
// link.click();
// 촬영한 이미지를 배열에 추가
photoArr.push(canvas.toDataURL());
// 이미지를 목록에 표시
const listItem = document.createElement("li");
const image = document.createElement("img");
image.style.width = "240px";
image.style.height = "180px";
image.src = canvas.toDataURL();
listItem.appendChild(image);
photoList.appendChild(listItem);
// 남은 사진 촬영 횟수 갱신
remainingCount--;
updateRemainingCount();
// 사진 촬영 횟수가 남아있을 경우 카운트다운 재시작
if (remainingCount > 0) {
startCountdown();
} else {
captureButton.disabled = true; // 사진 촬영 버튼 비활성화
stopAudio();
choicePhoto();
}
}
const selectPhotoItems = Array.from(
selectPhotoList.querySelectorAll("li")
);
// selectedPhotoArr를 virtual frame에 넣기
function inputVirtualFrame() {
selectPhotoItems.forEach((item, index) => {
item.innerHTML = "";
const imageSrc = selectedPhotoArr[index];
if (imageSrc) {
const image = document.createElement("img");
image.src = imageSrc;
image.alt = `Selected Image ${index + 1}`;
item.appendChild(image);
}
});
}
// selectedPhotoArr를 frame에 넣기
function inputPhotoFrame() {
frameHoles.forEach((hole, index) => {
if (index >= selectedPhotoArr.length * 2) {
hole.innerHTML = "";
return false;
}
const imageSrc = selectedPhotoArr[index % selectedPhotoArr.length];
if (imageSrc) {
const image = document.createElement("img");
image.src = imageSrc;
image.alt = `Selected Image ${index + 1}`;
image.classList.add("selected-image");
hole.appendChild(image);
}
});
}
// 사진 몇개 골랐는지 체크 -> 버튼 활성화 관리
function checkSelectedPhoto() {
if (selectedPhotoArr.length !== 4) {
selectCompleteButtonEl.setAttribute("disabled", true);
} else {
selectCompleteButtonEl.removeAttribute("disabled");
}
}
const selectFrameSectionEl = document.getElementById(
"select-frame-section"
);
const frameImg1 = document.querySelector('#frame-img1');
const frameImg2 = document.querySelector('#frame-img2');
// 4장 다 고르면 프레임 고르는 섹션으로 넘어가기
function choiceFrame() {
// 화면 전환
photoChoiceSectionEl.classList.toggle("visibility-hidden");
photoOutputSectionEl.classList.toggle("visibility-hidden");
// 프레임 carousel item div 생성
frameArr.forEach((frame, index) => {
const divTag = document.createElement("div");
divTag.classList.add("select-frame-item");
divTag.id = `frameImg${index}`;
divTag.addEventListener('click', () => {
frameImg1.src = frameArr[index].imgSrc;
frameImg2.src = frameArr[index].imgSrc;
})
// 로고 src가 없다면
if(!frameArr[index].logoSrc) {
const textTag = document.createElement('div');
textTag.classList.add('select-frame-item-name');
textTag.innerHTML = frameArr[index].name;
divTag.appendChild(textTag);
} else {
divTag.style.backgroundImage = `url('${frameArr[index].logoSrc}')`;
divTag.style.backgroundSize = 'contain';
}
selectFrameSectionEl.appendChild(divTag);
});
}
selectCompleteButtonEl.addEventListener("click", () => {
choiceFrame();
});
// 사진 고르기 기능
function choicePhoto() {
photoCaptureSectionEl.classList.toggle("visibility-hidden"); // 웹캠 가리기
photoChoiceSectionEl.classList.toggle("visibility-hidden"); // 사진 리스트 보여주기
const photoArrItems = Array.from(
photoList.querySelectorAll("#photoList > li")
);
// 고른 사진 배열에 넣기
for (let i = 0; i < photoArrItems.length; i++) {
const photoItem = photoArrItems[i];
photoItem.addEventListener("click", function () {
if (photoItem.classList.contains("selected")) {
photoItem.classList.remove("selected");
const imgSrc = photoItem.querySelector("img").src;
const index = selectedPhotoArr.indexOf(imgSrc);
if (index > -1) {
selectedPhotoArr.splice(index, 1);
}
} else {
if (selectedPhotoArr.length >= 4) {
return; // 최대 4개의 사진을 선택했다면 더이상 선택하지 못함
}
photoItem.classList.add("selected");
const imgSrc = photoItem.querySelector("img").src;
selectedPhotoArr.push(imgSrc);
}
checkSelectedPhoto();
inputPhotoFrame();
inputVirtualFrame();
});
}
}
// 완성된 사진 다운로드
function downloadImage() {
// HTML 요소를 캡처하여 캔버스에 그림
const element = document.getElementById("memorism-photo");
html2canvas(element, { scale: 2 }).then(function (canvas) {
// 캔버스를 이미지 데이터 URL로 변환합니다.
const image = canvas.toDataURL("image/png");
// 가상 링크를 생성하여 이미지 다운로드를 트리거
const link = document.createElement("a");
link.href = image;
link.download = "memorism.png";
link.click();
});
}
downloadButtonEl.addEventListener("click", downloadImage);
// 사진 촬영 시작
function initialize() {
descriptionSectionEl.classList.toggle("visibility-hidden");
photoCaptureSectionEl.classList.toggle("visibility-hidden");
remainingCount = maxCount;
updateRemainingCount();
if (remainingCount > 0) {
startCountdown();
} else {
captureButton.disabled = true; // 사진 촬영 버튼 비활성화
}
}
// OpenCV.js 로드 후 실행될 함수
function onOpenCvReady() {
navigator.mediaDevices
.getUserMedia({ video: true })
.then((stream) => {
videoElement.srcObject = stream;
videoElement.play();
})
.catch((error) => {
console.error("Error accessing webcam:", error);
});
captureButton.addEventListener("click", () => {
capturePhoto();
});
}
startButtonEl.addEventListener("click", initialize);
</script>
</body>
</html>