-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
91 lines (74 loc) · 3.78 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/html2canvas.min.js"></script>
<style>
:root {
--font-system: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; /* https://css-tricks.com/snippets/css/system-font-stack */
--text-color: #000;
--bg-color: #eee;
--bg-color-alt: #000;
--featured-color: #03f;
--featured-color-hover: #69f;
--highlight-color: #fcd700;
}
html, body, body div {margin: 0; padding: 0; border: 0; font-family: var(--font-system); font-size: 100%; vertical-align: baseline; background: transparent;}
button {appearance: none; background-color: var(--featured-color); border: none; color: #fff; font-size: 1rem; padding: .75rem;-webkit-appearance: none;cursor: pointer; font-weight: bold; text-transform: uppercase; border-radius: 6px;}
button:hover {background-color: var(--featured-color-hover);}
#socialBox {text-align: left; position: relative; width: 1200px; height: 600px; padding: 3rem; background: var(--bg-color); color: var(--text-color); margin: 2rem auto; box-sizing: border-box; border-top: 1rem solid var(--highlight-color);}
#socialBox .title {line-height: 5rem; font-weight: bold; font-size: 5rem;}
#socialBox .description {line-height: 4rem; font-size: 3rem; margin-bottom: 1rem;}
#socialBox .logo {position: absolute; z-index: 100; right: 3rem; bottom: 7rem;}
#socialBox .logo.emoji {font-size: 7rem;}
#socialBox .footer {text-align: right; position: absolute; bottom: 0; right: 0; left: 0; background: var(--bg-color-alt); color: rgba(255,255,255,1); font-weight: bold; line-height: 5rem; font-size: 2rem; padding: 0 3rem;}
#socialBox .footer:before {content: ''; position: absolute; bottom: 100%; left: 0; right: 0; background: var(--bg-color-alt); height: 2rem;}
#socialBox .footer:after {content: ''; position: absolute; bottom: 100%; left: 0; right: 0; background: var(--bg-color); height: 2rem; border-bottom-left-radius: 1rem; border-bottom-right-radius: 1rem;}
div#output:not(:empty) {width: 1200px; height: 600px; margin: 0 auto;}
.buttonHolder {text-align: center; margin: 2rem 0;}
#download {display: none;}
</style>
</head>
<body>
<div id="socialBox">
<div contenteditable="true" class="title">Generate social media images for your content</div>
<div contenteditable="true" class="description">Edit the HTML and CSS as you like, tweak the text in the preview before converting it to a canvas element, then save as a PNG.</div>
<div contenteditable="true" class="logo emoji">👍</div>
<div contenteditable="true" class="footer">github.com/murtaugh/social-image-generator</div>
</div>
<div class="buttonHolder">
<button id="capture">capture</button>
</div>
<div id="output"></div>
<div class="buttonHolder">
<button id="download">download</button>
</div>
<script>
function captureDiv() {
let socialBox = document.getElementById('socialBox');
let output = document.getElementById('output');
let capture = document.getElementById('capture');
let download = document.getElementById('download');
output.innerHTML = '';
html2canvas(socialBox).then(
function (canvas) {
output.appendChild(canvas);
capture.innerHTML = 're-capture';
download.style.display = 'inline';
}
);
};
document.getElementById('capture').addEventListener('click', captureDiv);
document.getElementById('download').addEventListener('click', function(e) {
let canvasUrl = document.getElementById('output').getElementsByTagName('canvas')[0].toDataURL("image/png", 0.5);
console.log(canvasUrl);
const el = document.createElement('a');
el.href = canvasUrl;
el.download = "{url_title}-" + Date.now();
el.click();
el.remove();
});
</script>
</body>
</html>