-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (124 loc) · 3.33 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
<!doctype html>
<html>
<head>
<title>FREE AND SIMPLE PFP GENERATOR</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<!--<meta name="viewport" content="width=device-width, initial-scale=1" />-->
<link rel="stylesheet" href="app.css">
<script src="jquery.min.js"></script>
<script src="fabric.min.js"></script>
<script src="FileSaver.js"></script>
<script src="canvas-toBlob.js"></script>
</head>
<body>
<span class="bg"></span>
<article>
<h1>FREE AND SIMPLE PFP GENERATOR</h1>
<input type="file" id="uploader" oninput="checkInput()" accept="image/*">
<p><canvas id="c">Your browser does not support the canvas element.</canvas></p
<p>
<button onclick="selectFile()">PILIH FILE</button>
<button id="save" onclick="dL()" disabled>DOWNLOAD</button>
<button id="shared" disabled>SHARE</button>
</p>
<h1>Tutorial:</h1>
<ol>
<li>Klik <strong>Pilih File</strong> dan tambahkan foto terbaik Anda.</li>
<li>Lalu pas kan foto Anda dalam bingkai dengan cara menggeser foto.</li>
<li>Jika sudah pas, silahkan klik <strong>Download</strong> dan <strong>Share</strong> media sosial Anda.</li>
</ol>
</article>
<!-- app.js -->
<script src="bg.js"></script>
<script>
var canvas = new fabric.Canvas('c');
canvas.setWidth(600);
canvas.setHeight(600);
canvas.selection = false;
canvas.backgroundColor = 'gray';
document.getElementById("uploader").onchange = function(e) {
var reader = new FileReader();
reader.onload = function(e) {
var image = new Image();
image.src = e.target.result;
image.onload = function() {
var img = new fabric.Image(image);
img.set({
borderColor: 'gray',
cornerColor: 'black',
transparentCorners: true,
left: 100,
top: 60
});
img.scaleToWidth(400);
canvas.add(img).setActiveObject(img).renderAll();
}
}
reader.readAsDataURL(e.target.files[0]);
}
fabric.Image.fromURL('image.png', function(img) {
canvas.setOverlayImage(img, canvas.renderAll.bind(canvas));
});
canvas.on({
'object:moving': function(e) {
e.target.opacity = 0.6;
},
'object:modified': function(e) {
e.target.opacity = 1;
}
});
function selectFile() {
document.getElementById("uploader").click();
}
$("#save").click(function(){
$("#c").get(0).toBlob(function(blob){
saveAs(blob, "image.png");
});
});
// share
document.getElementById("shared").addEventListener("click", () => {
alert("Bagikan Twibbon ini ke media sosial Anda?");
const dataUrl = c.toDataURL();
fetch(dataUrl)
.then(res => res.blob())
.then(blob => {
//console.log(blob)
const filesArray = [new File([blob], 'image.png', { type: blob.type, lastModified: new Date().getTime() })];
console.log(filesArray);
const shareData = {
title: "FREE AND SIMPLE PFP GENERATOR",
text: "FREE AND SIMPLE PFP GENERATOR",
url: "https://kisahklasik.github.io/twibbone/",
files: filesArray
};
console.log(shareData);
if (navigator.share) {
navigator.share(
shareData
)
.then(() => alert("Terima kasih telah berbagi."))
.catch(error => alert("Bagikan dibatalkan!", error));
} else {
alert('navigator.share not available');
}
})
});
</script>
<script>
function dL() {
var input = document.getElementById("uploader");
input.disabled = true;
}
</script>
<script>
function checkInput() {
var input = document.getElementById('uploader').value;
var button = document.getElementById('save');
var share = document.getElementById('shared');
button.disabled = input === '';
share.disabled = input === '';
}
</script>
</body>
</html>