-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
259 lines (228 loc) · 10 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
<!DOCTYPE html>
<html lang="ko" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>축하합니다 짤 생성기</title>
<meta name='description' content='-아무 이유 없음-' />
<!-- Facebook Meta Tags -->
<meta property="og:url" content="https://congrats.rwe.kr">
<meta property="og:type" content="website">
<meta property="og:title" content="축하합니다 짤 생성기">
<meta property="og:description" content="- 아무 이유 없음 -">
<meta property="og:image" content="https://congrats.rwe.kr/static/thumbnail.png">
<!-- Twitter Meta Tags -->
<meta name="twitter:card" content="summary_large_image">
<meta property="twitter:domain" content="congrats.rwe.kr">
<meta property="twitter:url" content="https://congrats.rwe.kr">
<meta name="twitter:title" content="축하합니다 짤 생성기">
<meta name="twitter:description" content="-아무 이유 없음-">
<meta name="twitter:image" content="https://congrats.rwe.kr/static/thumbnail.png">
<link rel="apple-touch-icon" sizes="180x180" href="/resources/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/resources/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/resources/favicon/favicon-16x16.png">
<link rel="manifest" href="/resources/favicon/site.webmanifest">
<style type="text/css">
@font-face {
font-family: 'ChosunGs';
src: url('https://fastly.jsdelivr.net/gh/projectnoonnu/[email protected]/ChosunGs.woff') format('woff');
font-weight: normal;
font-style: normal;
}
body {
font-family: 'ChosunGs', 'gungsuh', sans-serif !important;
}
</style>
<script>
document.addEventListener("DOMContentLoaded", () => {
document.querySelector('form').addEventListener('submit', (event) => { event.preventDefault(); });
let input = document.getElementById('floating-input');
input.addEventListener('input', () => { handleInput(input) });
});
function handleInput(input) {
const maxLength = 4;
if (input.value.length > maxLength) {
input.classList.add('is-invalid');
input.value = input.value.slice(0, maxLength);
} else {
input.classList.remove('is-invalid');
}
if (input.value.length === 0) {
resetCanvas();
document.getElementById('save-button').style.display = 'none';
return;
}
updateCanvas(input.value);
}
function resetCanvas() {
const oldCanvas = document.getElementById('canvas');
const newCanvas = document.createElement('canvas');
newCanvas.id = 'canvas';
oldCanvas.parentNode.replaceChild(newCanvas, oldCanvas);
}
function updateCanvas(text) {
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
let image = new Image();
image.src = "./static/congrats.png";
image.crossOrigin = "anonymous";
image.onload = (() => {
canvas.width = 1024;
canvas.height = image.height * (1024 / image.width);
context.drawImage(image, 0, 0, 1024, image.height * (1024 / image.width));
drawTextOnCanvas(context, text);
document.getElementById('save-button').style.display = 'block';
});
}
function drawTextOnCanvas(context, text) {
if (text.length === 1) {
context.font = 'bold 46px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 70, 9);
context.fillText(text[0], 300, 250);
} else if (text.length === 2) {
context.font = 'bold 44px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 40, 9);
context.fillText(text[0], 300, 250);
context.font = 'bold 48px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 70, 8);
context.fillText(text[1], 300, 250);
} else if (text.length === 3) {
context.font = 'bold 42px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 0, 10);
context.fillText(text[0], 300, 250);
context.font = 'bold 46px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 70, 9);
context.fillText(text[1], 300, 250);
context.font = 'bold 48px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 76, 9);
context.fillText(text[2], 300, 250);
} else if (text.length === 4) {
context.font = 'bold 40px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, -30, 10);
context.fillText(text[0], 300, 250);
context.font = 'bold 42px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 70, 9);
context.fillText(text[1], 300, 250);
context.font = 'bold 46px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 72, 9);
context.fillText(text[2], 300, 250);
context.font = 'bold 48px ChosunGs';
context.fillStyle = '#101010';
context.transform(1, -0.025, 0, 1, 76, 12);
context.fillText(text[3], 300, 250);
}
}
function exportCanvasAsPNG(id, fileName) {
var canvasElement = document.getElementById(id);
var MIME_TYPE = "image/png";
var imgURL = canvasElement.toDataURL(MIME_TYPE);
var dlLink = document.createElement('a');
dlLink.download = fileName;
dlLink.href = imgURL;
dlLink.dataset.downloadurl = [MIME_TYPE, dlLink.download, dlLink.href].join(':');
document.body.appendChild(dlLink);
dlLink.click();
document.body.removeChild(dlLink);
}
</script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h2 class="mt-3">🎉 축하합니다 짤 생성기 🎉</h2>
<form class="form-floating mt-3">
<input type="text" class="form-control" id="floating-input">
<label for="floating-input">이름 (4글자까지 가능)</label>
</form>
<div class="row mt-3">
<canvas id="canvas"></canvas>
</div>
<div class="row mt-3" id="save-button" style="display: none">
<button class="btn btn-primary" onclick="exportCanvasAsPNG('canvas', '축하합니다_' + document.getElementById('floating-input').value)">저장하기</button>
</div>
<footer class="mt-3">
<small>
Made by gwanryo · <a href="https://github.com/gwanryo/congrats-for-no-reason" target="_blank">GitHub</a> · <a href="https://www.fmkorea.com/best/2594426530" target="_blank">Original</a> · <a href="https://noonnu.cc/font_page/416" target="_blank">Font</a>
</small>
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script>
/*!
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/)
* Copyright 2011-2024 The Bootstrap Authors
* Licensed under the Creative Commons Attribution 3.0 Unported License.
*/
(() => {
'use strict'
const getStoredTheme = () => localStorage.getItem('theme')
const setStoredTheme = theme => localStorage.setItem('theme', theme)
const getPreferredTheme = () => {
const storedTheme = getStoredTheme()
if (storedTheme) {
return storedTheme
}
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}
const setTheme = theme => {
if (theme === 'auto') {
document.documentElement.setAttribute('data-bs-theme', (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'))
} else {
document.documentElement.setAttribute('data-bs-theme', theme)
}
}
setTheme(getPreferredTheme())
const showActiveTheme = (theme, focus = false) => {
const themeSwitcher = document.querySelector('#bd-theme')
if (!themeSwitcher) {
return
}
const themeSwitcherText = document.querySelector('#bd-theme-text')
const activeThemeIcon = document.querySelector('.theme-icon-active use')
const btnToActive = document.querySelector(`[data-bs-theme-value="${theme}"]`)
const svgOfActiveBtn = btnToActive.querySelector('svg use').getAttribute('href')
document.querySelectorAll('[data-bs-theme-value]').forEach(element => {
element.classList.remove('active')
element.setAttribute('aria-pressed', 'false')
})
btnToActive.classList.add('active')
btnToActive.setAttribute('aria-pressed', 'true')
activeThemeIcon.setAttribute('href', svgOfActiveBtn)
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`
themeSwitcher.setAttribute('aria-label', themeSwitcherLabel)
if (focus) {
themeSwitcher.focus()
}
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
const storedTheme = getStoredTheme()
if (storedTheme !== 'light' && storedTheme !== 'dark') {
setTheme(getPreferredTheme())
}
})
window.addEventListener('DOMContentLoaded', () => {
showActiveTheme(getPreferredTheme())
document.querySelectorAll('[data-bs-theme-value]')
.forEach(toggle => {
toggle.addEventListener('click', () => {
const theme = toggle.getAttribute('data-bs-theme-value')
setStoredTheme(theme)
setTheme(theme)
showActiveTheme(theme, true)
})
})
})
})()
</script>
</body>
</html>