-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
777 lines (675 loc) · 30.2 KB
/
Copy pathscript.js
File metadata and controls
777 lines (675 loc) · 30.2 KB
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
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
// Enhanced Collage System JavaScript
class CollageSystem {
constructor() {
this.uploadedImages = [];
this.selectedLayout = null;
this.maxImages = 6;
this.minImages = 2;
// Initialize COLLAGE_LAYOUTS configuration
this.COLLAGE_LAYOUTS = {
2: [
{
id: '2x1',
name: '2×1 (Vertical)',
description: 'Two images stacked vertically',
grid: { rows: 2, cols: 1 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 }
]
},
{
id: '1x2',
name: '1×2 (Horizontal)',
description: 'Two images side by side',
grid: { rows: 1, cols: 2 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 }
]
}
],
3: [
{
id: '3x1',
name: '3×1 (Vertical)',
description: 'Three images stacked vertically',
grid: { rows: 3, cols: 1 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 3, col: 1, rowSpan: 1, colSpan: 1 }
]
},
{
id: '1x3',
name: '1×3 (Horizontal)',
description: 'Three images side by side',
grid: { rows: 1, cols: 3 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 3, rowSpan: 1, colSpan: 1 }
]
},
{
id: '2x2_3',
name: '2×2 with 1 empty',
description: 'Grid layout with one empty space',
grid: { rows: 2, cols: 2 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 }
]
}
],
4: [
{
id: '2x2',
name: '2×2 (Square)',
description: 'Four images in a square grid',
grid: { rows: 2, cols: 2 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 2, rowSpan: 1, colSpan: 1 }
]
},
{
id: '4x1',
name: '4×1 (Vertical)',
description: 'Four images stacked vertically',
grid: { rows: 4, cols: 1 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 3, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 4, col: 1, rowSpan: 1, colSpan: 1 }
]
},
{
id: '1x4',
name: '1×4 (Horizontal)',
description: 'Four images side by side',
grid: { rows: 1, cols: 4 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 3, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 4, rowSpan: 1, colSpan: 1 }
]
}
],
5: [
{
id: '5x1',
name: '5×1 (Vertical)',
description: 'Five images stacked vertically',
grid: { rows: 5, cols: 1 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 3, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 4, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 5, col: 1, rowSpan: 1, colSpan: 1 }
]
},
{
id: '1x5',
name: '1×5 (Horizontal)',
description: 'Five images side by side',
grid: { rows: 1, cols: 5 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 3, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 4, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 5, rowSpan: 1, colSpan: 1 }
]
},
{
id: '2x3_5',
name: '2×3 with 1 empty',
description: 'Grid layout with one empty space',
grid: { rows: 2, cols: 3 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 3, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 2, rowSpan: 1, colSpan: 1 }
]
}
],
6: [
{
id: '2x3',
name: '2×3',
description: 'Two rows, three columns',
grid: { rows: 2, cols: 3 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 3, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 3, rowSpan: 1, colSpan: 1 }
]
},
{
id: '3x2',
name: '3×2',
description: 'Three rows, two columns',
grid: { rows: 3, cols: 2 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 3, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 3, col: 2, rowSpan: 1, colSpan: 1 }
]
},
{
id: '6x1',
name: '6×1 (Vertical)',
description: 'Six images stacked vertically',
grid: { rows: 6, cols: 1 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 2, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 3, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 4, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 5, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 6, col: 1, rowSpan: 1, colSpan: 1 }
]
},
{
id: '1x6',
name: '1×6 (Horizontal)',
description: 'Six images side by side',
grid: { rows: 1, cols: 6 },
cells: [
{ row: 1, col: 1, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 2, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 3, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 4, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 5, rowSpan: 1, colSpan: 1 },
{ row: 1, col: 6, rowSpan: 1, colSpan: 1 }
]
}
]
};
this.init();
}
init() {
this.setupEventListeners();
this.setupDragAndDrop();
this.updateImageCount();
}
setupEventListeners() {
// File input
const fileInput = document.getElementById('fileInput');
const uploadArea = document.getElementById('uploadArea');
uploadArea.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', (e) => this.handleFileSelect(e));
// Layout filter
const imageCountFilter = document.getElementById('imageCountFilter');
imageCountFilter.addEventListener('change', (e) => this.filterLayouts(e.target.value));
// Control buttons
document.getElementById('createCollageBtn').addEventListener('click', () => this.createCollage());
document.getElementById('downloadBtn').addEventListener('click', () => this.downloadCollage());
document.getElementById('demoBtn').addEventListener('click', () => this.loadDemoImages());
document.getElementById('resetBtn').addEventListener('click', () => this.reset());
// Options
document.getElementById('spacing').addEventListener('input', (e) => {
document.getElementById('spacingValue').textContent = `${e.target.value}px`;
this.updateCollagePreview();
});
document.getElementById('borderRadius').addEventListener('input', (e) => {
document.getElementById('borderRadiusValue').textContent = `${e.target.value}px`;
this.updateCollagePreview();
});
document.getElementById('backgroundColor').addEventListener('change', () => this.updateCollagePreview());
document.getElementById('canvasSize').addEventListener('change', () => this.updateCollagePreview());
}
setupDragAndDrop() {
const uploadArea = document.getElementById('uploadArea');
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
uploadArea.addEventListener(eventName, this.preventDefaults, false);
});
['dragenter', 'dragover'].forEach(eventName => {
uploadArea.addEventListener(eventName, () => uploadArea.classList.add('dragover'), false);
});
['dragleave', 'drop'].forEach(eventName => {
uploadArea.addEventListener(eventName, () => uploadArea.classList.remove('dragover'), false);
});
uploadArea.addEventListener('drop', (e) => this.handleDrop(e), false);
}
preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
handleFileSelect(e) {
const files = Array.from(e.target.files);
this.processFiles(files);
}
handleDrop(e) {
const dt = e.dataTransfer;
const files = Array.from(dt.files);
this.processFiles(files);
}
processFiles(files) {
const imageFiles = files.filter(file => file.type.startsWith('image/'));
if (this.uploadedImages.length + imageFiles.length > this.maxImages) {
this.showError(`Maximum ${this.maxImages} images allowed`);
return;
}
imageFiles.forEach(file => {
const reader = new FileReader();
reader.onload = (e) => {
this.uploadedImages.push({
id: Date.now() + Math.random(),
file: file,
url: e.target.result,
name: file.name
});
this.updateUI();
};
reader.readAsDataURL(file);
});
}
updateUI() {
this.renderUploadedImages();
this.updateImageCount();
this.updateLayoutFilter();
this.populateLayoutOptions();
this.updateControlButtons();
}
renderUploadedImages() {
const container = document.getElementById('uploadedImages');
container.innerHTML = '';
this.uploadedImages.forEach((image, index) => {
const imageItem = document.createElement('div');
imageItem.className = 'image-item';
imageItem.draggable = true;
imageItem.dataset.index = index;
imageItem.innerHTML = `
<img src="${image.url}" alt="${image.name}">
<button class="image-remove" onclick="collageSystem.removeImage(${index})">×</button>
`;
// Setup drag and drop for reordering
imageItem.addEventListener('dragstart', (e) => {
e.dataTransfer.setData('text/plain', index);
imageItem.classList.add('dragging');
});
imageItem.addEventListener('dragend', () => {
imageItem.classList.remove('dragging');
});
imageItem.addEventListener('dragover', (e) => {
e.preventDefault();
});
imageItem.addEventListener('drop', (e) => {
e.preventDefault();
const draggedIndex = parseInt(e.dataTransfer.getData('text/plain'));
const targetIndex = parseInt(imageItem.dataset.index);
this.reorderImages(draggedIndex, targetIndex);
});
container.appendChild(imageItem);
});
}
removeImage(index) {
this.uploadedImages.splice(index, 1);
this.updateUI();
if (this.uploadedImages.length === 0) {
this.selectedLayout = null;
this.clearCollagePreview();
}
}
reorderImages(fromIndex, toIndex) {
if (fromIndex === toIndex) return;
const [removed] = this.uploadedImages.splice(fromIndex, 1);
this.uploadedImages.splice(toIndex, 0, removed);
this.updateUI();
this.updateCollagePreview();
}
updateImageCount() {
const count = this.uploadedImages.length;
const countElement = document.getElementById('imageCount');
countElement.textContent = `${count} image${count !== 1 ? 's' : ''} uploaded`;
if (count < this.minImages) {
countElement.style.color = '#e53e3e';
} else if (count > this.maxImages) {
countElement.style.color = '#e53e3e';
} else {
countElement.style.color = '#38a169';
}
}
updateLayoutFilter() {
const filter = document.getElementById('imageCountFilter');
const count = this.uploadedImages.length;
if (count >= this.minImages && count <= this.maxImages) {
filter.disabled = false;
filter.value = count.toString();
this.filterLayouts(count.toString());
} else {
filter.disabled = true;
filter.value = '';
}
}
filterLayouts(imageCount) {
if (!imageCount) {
this.populateLayoutOptions();
return;
}
this.populateLayoutOptions(parseInt(imageCount));
}
populateLayoutOptions(filterCount = null) {
const container = document.getElementById('layoutOptions');
const currentImageCount = this.uploadedImages.length;
if (currentImageCount < this.minImages) {
container.innerHTML = '<p class="layout-placeholder">Upload at least 2 images to see available layouts</p>';
return;
}
container.innerHTML = '';
// Determine which layouts to show
let layoutsToShow;
if (filterCount) {
layoutsToShow = this.COLLAGE_LAYOUTS[filterCount] || [];
} else {
// Show layouts for current image count and auto-suggest optimal layout
layoutsToShow = this.COLLAGE_LAYOUTS[currentImageCount] || [];
if (layoutsToShow.length > 0) {
this.autoSelectOptimalLayout(layoutsToShow);
}
}
if (layoutsToShow.length === 0) {
container.innerHTML = '<p class="layout-placeholder">No layouts available for selected image count</p>';
return;
}
layoutsToShow.forEach((layout, index) => {
const layoutOption = document.createElement('div');
layoutOption.className = 'layout-option';
layoutOption.dataset.layoutId = layout.id;
layoutOption.setAttribute('role', 'button');
layoutOption.setAttribute('tabindex', '0');
layoutOption.setAttribute('aria-label', `Select ${layout.name} layout`);
if (this.selectedLayout && this.selectedLayout.id === layout.id) {
layoutOption.classList.add('selected');
}
layoutOption.innerHTML = `
<div class="layout-preview" style="display: grid; grid-template-rows: repeat(${layout.grid.rows}, 1fr); grid-template-columns: repeat(${layout.grid.cols}, 1fr); height: 80px; gap: 3px; padding: 8px; background: #f7fafc; border-radius: 6px; margin-bottom: 10px;">
${this.createLayoutPreviewCells(layout)}
</div>
<div class="layout-name" style="font-weight: 600; color: #2d3748; font-size: 0.9rem;">${layout.name}</div>
<div class="layout-description" style="font-size: 0.8rem; color: #718096; margin-top: 5px;">${layout.description}</div>
`;
layoutOption.addEventListener('click', () => this.selectLayout(layout));
container.appendChild(layoutOption);
});
}
createLayoutPreviewCells(layout) {
const cells = [];
// Create grid cells for visual preview
for (let row = 1; row <= layout.grid.rows; row++) {
for (let col = 1; col <= layout.grid.cols; col++) {
const hasImage = layout.cells.some(cell =>
cell.row === row && cell.col === col
);
cells.push(`<div class="layout-preview-cell ${hasImage ? '' : 'empty'}"></div>`);
}
}
return cells.join('');
}
autoSelectOptimalLayout(layouts) {
// Auto-suggest the first layout (usually the most optimal)
if (layouts.length > 0 && !this.selectedLayout) {
this.selectLayout(layouts[0]);
}
}
selectLayout(layout) {
this.selectedLayout = layout;
// Update UI
document.querySelectorAll('.layout-option').forEach(option => {
option.classList.remove('selected');
});
const selectedOption = document.querySelector(`[data-layout-id="${layout.id}"]`);
if (selectedOption) {
selectedOption.classList.add('selected');
}
this.updateCollagePreview();
this.updateControlButtons();
}
updateCollagePreview() {
if (!this.selectedLayout || this.uploadedImages.length === 0) {
this.clearCollagePreview();
return;
}
const canvas = document.getElementById('collageCanvas');
const spacing = document.getElementById('spacing').value;
const borderRadius = document.getElementById('borderRadius').value;
const backgroundColor = document.getElementById('backgroundColor').value;
// Set CSS variables
canvas.style.setProperty('--spacing', `${spacing}px`);
canvas.style.setProperty('--border-radius', `${borderRadius}px`);
canvas.style.backgroundColor = backgroundColor;
// Create collage grid
const grid = document.createElement('div');
grid.className = 'collage-grid';
grid.style.gridTemplateRows = `repeat(${this.selectedLayout.grid.rows}, 1fr)`;
grid.style.gridTemplateColumns = `repeat(${this.selectedLayout.grid.cols}, 1fr)`;
// Create cells
const totalCells = this.selectedLayout.grid.rows * this.selectedLayout.grid.cols;
const cells = [];
for (let row = 1; row <= this.selectedLayout.grid.rows; row++) {
for (let col = 1; col <= this.selectedLayout.grid.cols; col++) {
const cellData = this.selectedLayout.cells.find(cell =>
cell.row === row && cell.col === col
);
const cell = document.createElement('div');
cell.className = 'collage-cell';
cell.style.gridRow = `${row}`;
cell.style.gridColumn = `${col}`;
if (cellData) {
const imageIndex = this.selectedLayout.cells.indexOf(cellData);
if (this.uploadedImages[imageIndex]) {
const img = document.createElement('img');
img.src = this.uploadedImages[imageIndex].url;
img.alt = this.uploadedImages[imageIndex].name;
cell.appendChild(img);
}
} else {
cell.classList.add('empty');
}
grid.appendChild(cell);
}
}
canvas.innerHTML = '';
canvas.appendChild(grid);
}
clearCollagePreview() {
const canvas = document.getElementById('collageCanvas');
canvas.innerHTML = '<div class="canvas-placeholder"><p>Your collage will appear here</p></div>';
}
updateControlButtons() {
const createBtn = document.getElementById('createCollageBtn');
const downloadBtn = document.getElementById('downloadBtn');
const canCreate = this.uploadedImages.length >= this.minImages &&
this.uploadedImages.length <= this.maxImages &&
this.selectedLayout;
createBtn.disabled = !canCreate;
downloadBtn.disabled = !canCreate;
}
createCollage() {
if (!this.selectedLayout || this.uploadedImages.length === 0) {
this.showError('Please select images and a layout first');
return;
}
this.updateCollagePreview();
this.showSuccess('Collage created successfully!');
}
async downloadCollage() {
if (!this.selectedLayout || this.uploadedImages.length === 0) {
this.showError('Please create a collage first');
return;
}
try {
const canvas = await this.generateCanvasFromCollage();
const link = document.createElement('a');
link.download = `collage-${Date.now()}.png`;
link.href = canvas.toDataURL();
link.click();
this.showSuccess('Collage downloaded successfully!');
} catch (error) {
this.showError('Failed to download collage');
console.error(error);
}
}
async generateCanvasFromCollage() {
const canvasSize = document.getElementById('canvasSize').value;
const [width, height] = canvasSize.split('x').map(Number);
const spacing = parseInt(document.getElementById('spacing').value);
const borderRadius = parseInt(document.getElementById('borderRadius').value);
const backgroundColor = document.getElementById('backgroundColor').value;
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
// Fill background
ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, width, height);
// Calculate cell dimensions
const cols = this.selectedLayout.grid.cols;
const rows = this.selectedLayout.grid.rows;
const cellWidth = (width - spacing * (cols + 1)) / cols;
const cellHeight = (height - spacing * (rows + 1)) / rows;
// Draw images
for (let i = 0; i < this.selectedLayout.cells.length && i < this.uploadedImages.length; i++) {
const cell = this.selectedLayout.cells[i];
const image = this.uploadedImages[i];
const x = spacing + (cell.col - 1) * (cellWidth + spacing);
const y = spacing + (cell.row - 1) * (cellHeight + spacing);
const img = new Image();
await new Promise((resolve) => {
img.onload = resolve;
img.src = image.url;
});
// Apply border radius if specified
if (borderRadius > 0) {
ctx.save();
this.roundRect(ctx, x, y, cellWidth, cellHeight, borderRadius);
ctx.clip();
}
ctx.drawImage(img, x, y, cellWidth, cellHeight);
if (borderRadius > 0) {
ctx.restore();
}
}
return canvas;
}
roundRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
loadDemoImages() {
// Create demo images using SVG data URLs
const demoImages = [
{
id: Date.now() + 1,
file: null,
url: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjE1MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjRkY2QjZCIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIyMCIgZmlsbD0iI2ZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkRlbW8gSW1hZ2UgMTwvdGV4dD48L3N2Zz4=',
name: 'demo1.svg'
},
{
id: Date.now() + 2,
file: null,
url: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjE1MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjNEVDREMxIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIyMCIgZmlsbD0iI2ZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkRlbW8gSW1hZ2UgMjwvdGV4dD48L3N2Zz4=',
name: 'demo2.svg'
},
{
id: Date.now() + 3,
file: null,
url: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAwIiBoZWlnaHQ9IjE1MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjNDVCN0QxIi8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIyMCIgZmlsbD0iI2ZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkRlbW8gSW1hZ2UgMzwvdGV4dD48L3N2Zz4=',
name: 'demo3.svg'
}
];
this.uploadedImages = demoImages;
this.updateUI();
this.showSuccess('Demo images loaded! You can now test the layout options.');
}
reset() {
this.uploadedImages = [];
this.selectedLayout = null;
// Reset UI
document.getElementById('fileInput').value = '';
document.getElementById('imageCountFilter').value = '';
document.getElementById('imageCountFilter').disabled = true;
this.updateUI();
this.clearCollagePreview();
}
showError(message) {
this.showNotification(message, 'error');
}
showSuccess(message) {
this.showNotification(message, 'success');
}
showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.textContent = message;
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
padding: 12px 20px;
border-radius: 6px;
color: white;
font-weight: 600;
z-index: 1000;
animation: slideIn 0.3s ease;
max-width: 300px;
word-wrap: break-word;
`;
if (type === 'error') {
notification.style.backgroundColor = '#e53e3e';
} else if (type === 'success') {
notification.style.backgroundColor = '#38a169';
} else {
notification.style.backgroundColor = '#3182ce';
}
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideOut 0.3s ease';
setTimeout(() => notification.remove(), 300);
}, 3000);
}
}
// Add CSS for notifications
const notificationStyles = document.createElement('style');
notificationStyles.textContent = `
@keyframes slideIn {
from { transform: translateX(100%); opacity: 0; }
to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
from { transform: translateX(0); opacity: 1; }
to { transform: translateX(100%); opacity: 0; }
}
`;
document.head.appendChild(notificationStyles);
// Initialize the collage system when the page loads
let collageSystem;
document.addEventListener('DOMContentLoaded', () => {
collageSystem = new CollageSystem();
});