-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_image.html
More file actions
551 lines (484 loc) · 23.5 KB
/
join_image.html
File metadata and controls
551 lines (484 loc) · 23.5 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>ProMerge - Smart Image Joiner</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;800&display=swap" rel="stylesheet">
<style>
:root {
--primary: #6366f1;
--primary-glow: rgba(99, 102, 241, 0.4);
--bg: #fdfdff;
--surface: #ffffff;
--border: #eef2f6;
--text: #0f172a;
--text-light: #64748b;
--radius: 20px;
--shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.05), 0 20px 40px -10px rgba(0, 0, 0, 0.03);
--liquid-shadow: 0 20px 50px rgba(99, 102, 241, 0.15);
--bar-height: 90px;
}
body {
font-family: 'Plus Jakarta Sans', sans-serif;
margin: 0;
background: var(--bg);
color: var(--text);
line-height: 1.5;
/* Ensure space for the fixed bar */
padding-bottom: var(--bar-height);
}
.container { max-width: 800px; margin: 0 auto; padding: 20px; }
.header { text-align: center; margin-bottom: 25px; }
.header h2 {
margin: 0;
font-weight: 800;
letter-spacing: -0.5px;
background: linear-gradient(135deg, #1e293b 0%, #6366f1 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
/* Upload Area */
.upload-area {
border: 2px dashed #cbd5e1;
background: var(--surface);
border-radius: var(--radius);
padding: 40px 20px;
text-align: center;
cursor: pointer;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
margin-bottom: 20px;
box-shadow: var(--shadow);
}
.upload-area:hover {
border-color: var(--primary);
transform: translateY(-2px);
box-shadow: var(--liquid-shadow);
background: #f8faff;
}
.upload-icon-svg {
width: 48px; height: 48px; margin-bottom: 12px;
filter: drop-shadow(0 4px 6px var(--primary-glow));
}
.upload-text { font-weight: 700; color: #1e293b; font-size: 1.1rem; }
input[type="file"] { display: none; }
/* Scroll Area */
.preview-scroll-container {
display: flex;
gap: 16px;
overflow-x: auto;
padding: 10px 5px 25px 5px;
margin-bottom: 20px;
scroll-behavior: smooth;
}
.preview-scroll-container::-webkit-scrollbar { height: 6px; }
.preview-scroll-container::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 10px; }
.preview-card {
background: var(--surface);
border: 1px solid var(--border);
border-radius: 16px;
padding: 14px;
position: relative;
box-shadow: var(--shadow);
display: flex;
flex-direction: column;
align-items: center;
min-width: 140px;
flex-shrink: 0;
transition: transform 0.2s;
}
.preview-card:hover { transform: scale(1.02); }
.thumb-icon {
width: 40px; height: 40px; background: #f1f5f9;
border-radius: 10px; display: flex; align-items: center;
justify-content: center; margin-bottom: 10px; color: var(--primary);
}
.thumb-img-preview {
width: 40px; height: 40px; object-fit: cover; border-radius: 10px; margin-bottom: 10px;
}
.preview-info {
font-size: 12px; margin-top: 2px;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
width: 100%; font-weight: 600; text-align: center;
}
.card-actions { display: flex; gap: 6px; width: 100%; margin-top: 10px; }
.action-btn-small {
flex: 1; border: 1px solid var(--border); background: #f8fafc;
border-radius: 8px; padding: 6px; cursor: pointer;
display: flex; align-items: center; justify-content: center;
}
.action-btn-small:hover { background: #fff; border-color: var(--primary); color: var(--primary); }
.view-trigger-btn {
background: #f1f5f9; border: none; color: #475569;
border-radius: 8px; padding: 6px; font-size: 11px; font-weight: 700;
cursor: pointer; width: 100%; margin-top: 8px; transition: 0.2s;
}
.view-trigger-btn:hover { background: var(--primary); color: white; }
.remove-btn {
position: absolute; top: -8px; right: -8px;
background: #1e293b; color: white; border: none;
border-radius: 50%; width: 24px; height: 24px;
cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center;
box-shadow: 0 4px 6px rgba(0,0,0,0.1); z-index: 10;
}
/* Controls Section */
.controls {
background: var(--surface);
padding: 24px;
border-radius: var(--radius);
box-shadow: var(--shadow);
margin-bottom: 20px;
border: 1px solid var(--border);
}
.form-row { display: flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
.form-group { flex: 1; min-width: 140px; }
label { font-weight: 700; font-size: 0.85rem; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; display: block; }
select, input[type="number"] {
width: 100%; padding: 12px; border: 1.5px solid var(--border); border-radius: 12px; box-sizing: border-box; background: #f8fafc; font-family: inherit; font-weight: 600;
}
select:focus, input:focus { outline: none; border-color: var(--primary); background: #fff; }
/* Color Picker */
.color-scroll-container { display: flex; gap: 12px; overflow-x: auto; padding: 5px 2px 10px; scrollbar-width: none; }
.color-circle {
width: 34px; height: 34px; border-radius: 10px; border: 2px solid transparent;
cursor: pointer; flex-shrink: 0; transition: 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.color-circle.active { border-color: var(--primary); transform: translateY(-3px); box-shadow: 0 5px 10px rgba(99,102,241,0.2); }
.custom-picker-circle { background: conic-gradient(from 180deg, #ff0000, #ffff00, #00ff00, #00ffff, #0000ff, #ff00ff, #ff0000); position: relative; }
.hidden-color-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
/* --- FIXED BOTTOM BAR STYLES --- */
.bottom-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: rgba(255, 255, 255, 0.85);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
border-top: 1px solid var(--border);
padding: 15px 20px;
display: flex;
justify-content: center;
z-index: 50; /* Above content, below modals */
box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.05);
}
.bottom-bar-inner {
width: 100%;
max-width: 800px;
}
/* Action Button */
.action-btn {
width: 100%; padding: 16px;
background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
color: white; border: none; border-radius: 16px;
font-size: 16px; font-weight: 800; cursor: pointer;
box-shadow: 0 10px 25px -5px rgba(99, 102, 241, 0.4);
transition: all 0.3s;
}
.action-btn:hover { transform: translateY(-2px); box-shadow: 0 15px 30px -5px rgba(99, 102, 241, 0.5); }
.action-btn:active { transform: translateY(0); }
/* Modals */
.modal-overlay {
position: fixed; inset: 0; background: rgba(15, 23, 42, 0.8);
backdrop-filter: blur(8px); display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.active { display: flex; }
.modal-box {
background: white; width: 90%; max-width: 480px;
border-radius: 24px; padding: 32px; text-align: center;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
max-height: 90vh; overflow-y: auto;
}
.progress-bar { height: 10px; background: #f1f5f9; border-radius: 10px; overflow: hidden; margin: 20px 0; }
.progress-fill { height: 100%; background: var(--primary); width: 0%; transition: width 0.3s ease; }
.result-preview-img {
max-width: 100%; max-height: 280px; object-fit: contain;
border-radius: 12px; margin: 20px 0; border: 1px solid var(--border);
background-image: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #f0f0f0 75%), linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
background-size: 20px 20px;
background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}
.viewer-img { max-width: 100%; max-height: 85vh; border-radius: 12px; }
.close-viewer { position: fixed; top: 20px; right: 20px; color: white; font-size: 40px; cursor: pointer; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>Merge Studio</h2>
</div>
<!-- Upload Section -->
<div class="upload-area" onclick="document.getElementById('fileInput').click()">
<svg class="upload-icon-svg" viewBox="0 0 24 24" fill="none" stroke="#6366f1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/>
</svg>
<div class="upload-text">Import Media</div>
<div style="font-size: 13px; color: var(--text-light); margin-top:6px; font-weight: 500;">Supports High-Res JPG, PNG & WebP</div>
</div>
<input type="file" id="fileInput" multiple accept="image/*" onchange="handleSelection(this)">
<!-- Selected Images -->
<div id="previewContainer" class="preview-scroll-container">
<div id="emptyMsg" style="width:100%; text-align:center; color:var(--text-light); padding:30px; font-size:14px; border:2px dashed #f1f5f9; border-radius:16px; font-weight: 500;">
Waiting for images...
</div>
</div>
<!-- Configuration -->
<div class="controls">
<div class="form-row">
<div class="form-group">
<label>Flow Direction</label>
<select id="direction">
<option value="vertical">Vertical Stack</option>
<option value="horizontal">Side by Side</option>
</select>
</div>
<!-- New Sizing Control -->
<div class="form-group">
<label>Sizing Mode</label>
<select id="sizingMode">
<option value="uniform">Auto-Fit (Uniform)</option>
<option value="original">Original Dimensions</option>
</select>
</div>
</div>
<div class="form-row" style="margin-bottom: 20px;">
<div class="form-group">
<label>Gutter / Spacing (px)</label>
<input type="number" id="borderSize" value="0" min="0">
</div>
<div class="form-group">
<label>Background Color</label>
<div class="color-scroll-container" id="colorScrollContainer">
<div class="color-circle custom-picker-circle" id="customColorCircle">
<input type="color" class="hidden-color-input" onchange="selectCustomColor(this)">
</div>
</div>
<input type="hidden" id="selectedColorValue" value="#ffffff">
</div>
</div>
</div>
</div>
<!-- FIXED BOTTOM BAR -->
<div class="bottom-bar">
<div class="bottom-bar-inner">
<button class="action-btn" onclick="startMerge()">Generate Combined Image</button>
</div>
</div>
<!-- Progress -->
<div id="loadingModal" class="modal-overlay">
<div class="modal-box">
<h3 style="margin:0">Processing Media</h3>
<p style="color:var(--text-light); font-size:14px; margin-top:5px">Scaling layers and merging...</p>
<div class="progress-bar"><div id="pFill" class="progress-fill"></div></div>
<div id="pText" style="font-weight:700; color:var(--primary)">0%</div>
</div>
</div>
<!-- Success -->
<div id="resultModal" class="modal-overlay">
<div class="modal-box">
<div style="width:50px; height:50px; background:#dcfce7; color:#166534; border-radius:50%; display:flex; align-items:center; justify-content:center; margin:0 auto 15px;">
<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="3" viewBox="0 0 24 24"><polyline points="20 6 9 17 4 12"></polyline></svg>
</div>
<h3 style="margin:0">Merge Complete</h3>
<img id="resultImage" class="result-preview-img" src="">
<button class="action-btn" id="dlBtn">Download Result</button>
<button onclick="location.reload()" style="background:none; border:none; color:var(--text-light); font-weight:700; margin-top:20px; cursor:pointer;">Start New Project</button>
</div>
</div>
<!-- Alert -->
<div id="alertModal" class="modal-overlay">
<div class="modal-box" style="max-width: 320px;">
<div style="font-size: 40px; margin-bottom: 10px;">🛡️</div>
<h3 style="margin:0 0 10px 0;">Required</h3>
<p id="alertMsg" style="color:var(--text-light); margin-bottom:25px; font-size:14px;"></p>
<button class="action-btn" onclick="closeAlert()">Understood</button>
</div>
</div>
<!-- Viewer -->
<div id="imageViewerModal" class="modal-overlay" onclick="closeViewer()">
<div class="close-viewer">×</div>
<img id="viewerImage" class="viewer-img" onclick="event.stopPropagation()">
</div>
<canvas id="canvas" style="display:none;"></canvas>
<script>
let selectedFiles = [];
// --- Icons ---
const iconLeft = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="15 18 9 12 15 6"/></svg>`;
const iconRight = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="9 18 15 12 9 6"/></svg>`;
function showAlert(msg) {
document.getElementById('alertMsg').innerText = msg;
document.getElementById('alertModal').classList.add('active');
}
function closeAlert() {
document.getElementById('alertModal').classList.remove('active');
}
// Color Setup
const colors = ['#ffffff', '#000000', '#f8fafc', '#6366f1', '#ef4444', '#22c55e', '#eab308', '#a855f7'];
const colorContainer = document.getElementById('colorScrollContainer');
colors.forEach(color => {
const circle = document.createElement('div');
circle.className = 'color-circle';
circle.style.backgroundColor = color;
if(color === '#ffffff') circle.classList.add('active');
circle.onclick = () => {
document.querySelectorAll('.color-circle').forEach(c => c.classList.remove('active'));
circle.classList.add('active');
document.getElementById('selectedColorValue').value = color;
};
colorContainer.appendChild(circle);
});
function selectCustomColor(input) {
document.querySelectorAll('.color-circle').forEach(c => c.classList.remove('active'));
document.getElementById('customColorCircle').classList.add('active');
document.getElementById('selectedColorValue').value = input.value;
}
function handleSelection(input) {
if(input.files.length === 0) return;
selectedFiles = [...selectedFiles, ...Array.from(input.files)];
renderGrid();
input.value = '';
}
function renderGrid() {
const container = document.getElementById('previewContainer');
if(selectedFiles.length === 0) {
container.innerHTML = `<div id="emptyMsg" style="width:100%; text-align:center; color:var(--text-light); padding:30px; font-size:14px; border:2px dashed #f1f5f9; border-radius:16px; font-weight: 500;">Waiting for images...</div>`;
return;
}
container.innerHTML = '';
selectedFiles.forEach((file, index) => {
const url = URL.createObjectURL(file);
const div = document.createElement('div');
div.className = 'preview-card';
div.innerHTML = `
<button class="remove-btn" onclick="removeFile(${index})">×</button>
<img src="${url}" class="thumb-img-preview">
<div class="preview-info" title="${file.name}">${file.name}</div>
<div class="preview-info" style="color:var(--text-light); font-weight:400; font-size:10px">${(file.size/1024).toFixed(0)} KB</div>
<div class="card-actions">
<button class="action-btn-small" onclick="moveFile(${index}, -1)" ${index===0 ? 'disabled style="opacity:0.2"' : ''}>${iconLeft}</button>
<button class="action-btn-small" onclick="moveFile(${index}, 1)" ${index===selectedFiles.length-1 ? 'disabled style="opacity:0.2"' : ''}>${iconRight}</button>
</div>
<button class="view-trigger-btn" onclick="openViewer('${url}')">Preview</button>
`;
container.appendChild(div);
});
}
function removeFile(i) { selectedFiles.splice(i, 1); renderGrid(); }
function moveFile(i, d) {
const target = i + d;
if (target >= 0 && target < selectedFiles.length) {
[selectedFiles[i], selectedFiles[target]] = [selectedFiles[target], selectedFiles[i]];
renderGrid();
}
}
function openViewer(url) {
document.getElementById('viewerImage').src = url;
document.getElementById('imageViewerModal').classList.add('active');
}
function closeViewer() { document.getElementById('imageViewerModal').classList.remove('active'); }
const loadImage = file => new Promise(res => {
const img = new Image();
img.onload = () => res(img);
img.src = URL.createObjectURL(file);
});
async function startMerge() {
if(selectedFiles.length < 2) { showAlert("Add at least 2 images to join."); return; }
const border = parseInt(document.getElementById('borderSize').value) || 0;
const color = document.getElementById('selectedColorValue').value;
const isVertical = document.getElementById('direction').value === 'vertical';
const sizingMode = document.getElementById('sizingMode').value; // uniform or original
document.getElementById('loadingModal').classList.add('active');
const pFill = document.getElementById('pFill');
const pText = document.getElementById('pText');
// 1. Load all images
const loadedImages = [];
for(let i=0; i<selectedFiles.length; i++) {
pFill.style.width = ((i/selectedFiles.length)*50)+'%';
pText.innerText = 'Loading: ' + Math.round((i/selectedFiles.length)*50)+'%';
loadedImages.push(await loadImage(selectedFiles[i]));
}
// 2. Calculate Processed Dimensions based on Sizing Mode
let processedImages = [];
let canvasWidth = 0;
let canvasHeight = 0;
if (sizingMode === 'uniform') {
// --- Auto-Fit Logic (Scale to Largest) ---
if (isVertical) {
// Find widest image
const targetWidth = Math.max(...loadedImages.map(img => img.width));
canvasWidth = targetWidth + (border * 2);
// Calculate scale for each and total height
let totalContentHeight = 0;
processedImages = loadedImages.map(img => {
const scale = targetWidth / img.width;
const newH = img.height * scale;
totalContentHeight += newH;
return { img, x: 0, y: 0, w: targetWidth, h: newH };
});
canvasHeight = totalContentHeight + (border * (loadedImages.length + 1));
} else {
// Find tallest image
const targetHeight = Math.max(...loadedImages.map(img => img.height));
canvasHeight = targetHeight + (border * 2);
let totalContentWidth = 0;
processedImages = loadedImages.map(img => {
const scale = targetHeight / img.height;
const newW = img.width * scale;
totalContentWidth += newW;
return { img, x: 0, y: 0, w: newW, h: targetHeight };
});
canvasWidth = totalContentWidth + (border * (loadedImages.length + 1));
}
} else {
// --- Original Dimensions Logic ---
processedImages = loadedImages.map(img => ({ img, x:0, y:0, w: img.width, h: img.height }));
if (isVertical) {
const maxW = Math.max(...loadedImages.map(i => i.width));
canvasWidth = maxW + (border * 2);
canvasHeight = loadedImages.reduce((s, i) => s + i.height, 0) + (border * (loadedImages.length + 1));
} else {
const maxH = Math.max(...loadedImages.map(i => i.height));
canvasWidth = loadedImages.reduce((s, i) => s + i.width, 0) + (border * (loadedImages.length + 1));
canvasHeight = maxH + (border * 2);
}
}
// 3. Draw to Canvas
pFill.style.width = '75%';
pText.innerText = 'Rendering...';
await new Promise(r => setTimeout(r, 50));
const canvas = document.getElementById('canvas');
canvas.width = canvasWidth;
canvas.height = canvasHeight;
const ctx = canvas.getContext('2d');
ctx.fillStyle = color;
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
let currentX = border;
let currentY = border;
processedImages.forEach(obj => {
let drawX, drawY;
if (isVertical) {
drawX = currentX + (canvasWidth - (border*2) - obj.w) / 2;
drawY = currentY;
ctx.drawImage(obj.img, drawX, drawY, obj.w, obj.h);
currentY += obj.h + border;
} else {
drawX = currentX;
drawY = currentY + (canvasHeight - (border*2) - obj.h) / 2;
ctx.drawImage(obj.img, drawX, drawY, obj.w, obj.h);
currentX += obj.w + border;
}
});
pFill.style.width = '100%';
pText.innerText = 'Done!';
canvas.toBlob(blob => {
const url = URL.createObjectURL(blob);
document.getElementById('resultImage').src = url;
document.getElementById('dlBtn').onclick = () => saveAs(blob, "merged-pro.png");
document.getElementById('loadingModal').classList.remove('active');
document.getElementById('resultModal').classList.add('active');
}, 'image/png');
}
</script>
</body>
</html>