-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
448 lines (375 loc) · 13.9 KB
/
index.php
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Fabric</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- <link href="css/croppr.min.css" rel="stylesheet"/> -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.9/cropper.css">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
<style>
main{
min-height:80vh;
}
.hidden{
display:none;
}
.pattren_img{
width:500px;
height:500px;
background-repeat:no-repeat;
background-size:500px 500px;
}
.result{
}
</style>
</head>
<body class="">
<nav class="navbar navbar-expand-sm navbar-dark bg-cutom mb-3">
<div class="container">
<a class="navbar-brand top-logo" href="/">Fabric</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ml-auto">
<!--
<li class="nav-item">
<a href="#" class="nav-link">Login</a>
</li>
<li class="nav-item">
<a href="#" class="nav-link">Register</a>
</li> -->
</ul>
</div>
</div>
</nav>
<main>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6" >
<div class="row">
<!-- <h5 class="text-center">Tester</h5>-->
<div class="form-group col-sm-12">
<div class="card p-4 shadow-sm set-card">
<label for="input file"></label>
<div class="custom-file">
<input type="file" class="custom-file-input file2 input-set" data-image-selector=".image2" id="customFile" name="filename" value="sample.fxdr">
<label class="custom-file-label upload-set" for="customFile">DROP OR UPLOAD ARTWORK IMAGE HERE</label>
</div>
<div class="col-sm-6 col-6 d-none upload-image" id="uploaded_img">
<h6>Crop Image</h6>
<img class="image2 hidden img-fluid croppr" id="croppr" alt="Image will shown here" />
</div>
</div>
</div>
<!-- <div class="col-sm-12"> -->
<!-- <button type="submit" class="btn btn-primary btn-block btn-merge">Generate Meme</button> -->
<!-- </div> -->
</div>
<div class="col-sm-3">
<img class="test"/>
</div>
</div>
<div class="col-sm-6">
<div class="row">
<div class="form-group col-sm-12">
<div class="card shadow-sm p-4 set-card">
<label for="input file"></label>
<div class="custom-file">
<input type="file" class="custom-file-input file3 input-set" data-image-selector=".background-img" id="customFile1" name="filename" value="sample.fxdr">
<label class="custom-file-label upload-set hover" for="customFile">DROP OR UPLOAD BACKGROUND IMAGE HERE</label>
</div>
<div class=" col-sm-12 col-12 upload-image-2 " >
<img class="background-img d-block mx-auto img-fluid " alt="">
</div>
</div>
</div>
<!-- <div class="col-sm-12">
</div> -->
</div>
</div>
<div class="col-sm-12 text-center">
<button id="merger_fabric" class="btn btn-custom btn-lg">MERGE IMAGES</button>
<!-- <div style="position:relative;">
<canvas id="c1" style="width:500px; height:100px;"></canvas>
</div> -->
</div>
<div class="col-sm-2 result-set">
<h2 class="result3 d-none result-h6">RESULTS</h2>
</div>
<div class="col-sm-12">
<div class="card shadow p-4 d-none set-card" id="result4">
<div class="row">
<div class=" col-sm-6 result d-none mt-5" >
<div class="pattren_img d-block mx-auto border-1 p-1">
<canvas id="c" width="500" height="500"></canvas>
</div>
<!-- <canvas id="back_img" width="500" height="500"></canvas> -->
</div>
<div class="col-sm-6 result1 d-none mt-5">
<canvas id="final_image" class="d-block mx-auto" width="500" height="500"></canvas>
<h4 class="text-center result-h4">Final Result</h4>
<button id="download" class="btn btn-custom mt-2 d-block mx-auto">Download</button>
</div>
</div>
</div>
</div>
<!-- <div class="col-sm-6 col-6 mt-5 d-none" id="generated_img">
<h6>Generated Image</h6>
<img class="merged-image hidden img-fluid" alt="merged image" />
<canvas id="canvas" width="500" height="500" class="" style="position:relative">
</canvas>
</div> -->
</div>
</div>
<!-- <button id="download1">Download1</button> -->
<!-- <img src="" id="lala" alt=""> -->
</main>
<footer class="bg-cutom py-3 mt-3 ">
<div class="container">
<div class="row">
<div class="col-sm-6 "><p class="text-white text-md-left text-center font-weight-bold">CSI@2020 All rights reserved</p></div>
<div class="col-sm-6 "> <p class="text-md-right text-center text-white font-weight-bold">TEST</p></div>
</div>
</div>
</footer>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/downloadjs/1.4.8/download.min.js" ></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/4.1.0/fabric.min.js" ></script>
<!-- <script src="js/croppr.min.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.9/cropper.min.js"></script>
<script>
var data = {};
var img_src = "";
var cropped_url = "";
var background_img_src = "";
var cropInstance = {};
$(".custom-file-input").on("change", function() {
var fileName = $(this).val().split("\\").pop();
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
});
$('.file2').on('change', function() {
var reader = new FileReader(),
imageSelector = $(this).data('image-selector');
console.log(imageSelector);
console.log(this.files);
console.log(reader);
if (this.files[0]) {
reader.onload = function(e) {
console.log("add");
//imageSelector.cropper("destroy");
imageIsLoaded(e, imageSelector);
};
reader.readAsDataURL(this.files[0]);
}
});
function imageIsLoaded(e, imageSelector) {
$(imageSelector).attr('src', e.target.result);
img_src = e.target.result;
console.log(img_src);
$(imageSelector).removeClass('hidden');
$("#uploaded_img").removeClass('d-none');
var cropperImage = document.getElementById('croppr');
if(!jQuery.isEmptyObject(cropInstance)){
cropInstance.destroy();
}
console.log(cropInstance);
initCrop(cropperImage);
}
function initCrop(image){
cropInstance = new Cropper(image, {
ready(){
this.cropper.crop();
//this.cropper.destroy();
}
// ...options
});
}
$('.file3').on('change', function() {
var reader = new FileReader(),
imageSelector = $(this).data('image-selector');
console.log(imageSelector);
console.log(this.files);
console.log(reader);
if (this.files[0]) {
reader.onload = function(e) {
console.log("add");
backgroundImageIsLoaded(e, imageSelector);
};
reader.readAsDataURL(this.files[0]);
}
});
function backgroundImageIsLoaded(e, imageSelector){
$(imageSelector).attr('src', e.target.result);
background_img_src = e.target.result;
$(imageSelector).removeClass('hidden');
// $("#uploaded_img").removeClass('d-none');
}
$("#merger_fabric").on("click", mergeFabric);
var c1 = new fabric.Canvas('c1');
var canvas = new fabric.Canvas('c');
var coordinates = {};
var finalCanvas = document.getElementById("final_image");
canvas.on("after:render", function(){
$(".result1").removeClass("d-none");
var ao = canvas.getActiveObject();
console.log(ao);
if (ao) {
var bound = ao.getBoundingRect();
// canvas.contextContainer.strokeRect(
// bound.left,
// bound.top,
// bound.width,
// bound.height
// );
coordinates=bound;
// console.log(bound);
ftx = finalCanvas.getContext("2d");
ftx.clearRect(0, 0, finalCanvas.width, finalCanvas.height);
backFinalImg = new Image();
aboveFinalImg = new Image();
backFinalImg.src = background_img_src;
backFinalImg.onload = function(){
ftx.globalAlpha = 1;
ftx.drawImage(backFinalImg, 0, 0, 500, 500);
ftx.save();
aboveFinalImg.src = cropped_url.toDataURL();
aboveFinalImg.onload = function(){
// ftx.globalAlpha = 1;
if(ao.angle){
//ftx.translate(coordinates.width/2, coordinates.height/2);
ftx.rotate(ao.angle * Math.PI/180);
}
ftx.drawImage(aboveFinalImg, coordinates.left, coordinates.top, coordinates.width, coordinates.height);
ftx.restore();
}
}
}
})
function mergeFabric(){
// data = cropInstance.getValue();
// console.log(cropInstance.toDataURL('image/jpeg'));
// console.log(data);
// console.log(img_src);
// var canvas = document.getElementById('canvas2'),
// ctx = canvas.getContext('2d'),
// imageObj1 = new Image(),
// imageObj2 = new Image();
// // // imageObj3 = new Image();
// imageObj1.src = $('.background-img').attr('src');
// // // console.log(imageObj1);
// imageObj1.onload = function() {
// ctx.globalAlpha = 1;
// ctx.drawImage(imageObj1, 0, 0, 600, 600);
// // imageObj2.src = img_src;
// // imageObj2.onload = function() {
// }
cropped_url = cropInstance.getCroppedCanvas();
fabric.Image.fromURL(cropped_url.toDataURL(), function(oImg) {
c1.add(oImg);
});
fabric.Image.fromURL($('.background-img').attr('src'), function(oImg) {
c1.add(oImg);
});
// ctx.globalAlpha = 1;
// ctx.drawImage(imageObj2,data.x,data.y,data.width,data.height, 0, 0, 200, 200);
//var img = canvas.toDataURL('image/jpeg');
// $('.merged-image').attr('src', img);
// $('.merged-image').removeClass('hidden');
// $("#generated_img").removeClass('d-none');
// $('.merged-image').attr('src', img);
// $('.merged-image').removeClass('hidden');
// $("#generated_img").removeClass('d-none');
// // imageObj3.src = $('.image3').attr('src');
// // imageObj3.onload = function() {
// // ctx.globalAlpha = 0.5;
// // ctx.drawImage(imageObj3, 220, 220, 40, 40);
// // }
// }
// var backImgCanvas = document.getElementById("back_img");
// btcx = backImgCanvas.getContext("2d");
// backImgObj = new Image();
// backImgObj.src = background_img_src;
// backImgObj.onload = function(){
// btcx.globalAlpha = 1;
// btcx.drawImage(backImgObj, 0,0,500,500);
// };
if(img_src != "" && background_img_src != ""){
$(".result").removeClass("d-none");
$(".result3").removeClass("d-none");
$("#result4").removeClass("d-none");
$("#merger_fabric").addClass("d-none");
console.log(cropInstance);
cropped_url = cropInstance.getCroppedCanvas();
console.log(cropped_url.toDataURL());
// console.log(imageData);
console.log(cropped_url)
var pattren_img = $(".pattren_img");
pattren_img.css("background-image", "url("+background_img_src+")");
console.log(cropped_url);
fabric.Image.fromURL(cropped_url.toDataURL(), function(oImg) {
canvas.add(oImg);
});
}
else{
alert("dada");
// $("#merger_fabric").insertAfter("<div class='alert alert-danger'>Please Upload Both Images</div>");
}
};
// var imgg = $("#hehe");
// imgg.attr("src", img_src);
// imgg.width = "100";
// imgg.height = "200";
//canvas.add(imgInstance);
// function imageIsLoaded(e, imageSelector) {
// $(imageSelector).attr('src', e.target.result);
// img_src = e.target.result;
// $(imageSelector).removeClass('hidden');
// $("#uploaded_img").removeClass('d-none');
// const cropperImage = document.getElementById('croppr');
// cropInstance = new Cropper(cropperImage, {
// // ...options
// });
$("#download1").click(function(){
})
$('#download').click(function() {
// console.log($("#c1").toDataURL());
// download(c.toDataURL(), "test.jpg", "image/jpeg");
// console.log(coordinates);
// $("#lala").attr("src", cropped_url.toDataURL());
// console.log(cropped_url.toDataURL());
// var finalCanvas = document.getElementById("final_image");
// ftx = finalCanvas.getContext("2d");
// backFinalImg = new Image();
// aboveFinalImg = new Image();
// backFinalImg.src = background_img_src;
// backFinalImg.onload = function(){
// ftx.globalAlpha = 1;
// ftx.drawImage(backFinalImg, 0, 0, 500, 500);
// aboveFinalImg.src = cropped_url.toDataURL();
// aboveFinalImg.onload = function(){
// // ftx.globalAlpha = 1;
// ftx.drawImage(aboveFinalImg, coordinates.left, coordinates.top, coordinates.width, coordinates.height);
// }
// }
// var final_url = finalCanvas.toDataURL();
console.log(finalCanvas.toDataURL());
download(finalCanvas.toDataURL(),"fabric.png","image/png");
// );
// setTimeout(function(){
// window.location.reload();
// },2000)
});
console.log("abc")
</script>
</body>
</html>