-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
1666 lines (1460 loc) · 69.2 KB
/
index.html
File metadata and controls
1666 lines (1460 loc) · 69.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
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!--
✨ EditX Pro Studio by Kriztech ✨
Professional AI-Powered Web Image Editor
(c) 2024 Kriztech. All rights reserved.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>EditX Pro Studio by Kriztech | Professional Web Image Editor</title>
<meta name="description"
content="Edit, crop, resize, and enhance images instantly with EditX by Kriztech. Free online image editor with AI background removal, filters, and privacy-focused local processing.">
<meta name="keywords"
content="image editor, online photo editor, AI background remover, crop image, resize image, photo filters, Kriztech, EditX">
<meta name="author" content="Kriztech">
<meta name="theme-color" content="#0b0f1c">
<!-- SEO & Social -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://altkriz.github.io/editx/">
<meta property="og:title" content="EditX · Kriztech | AI-Powered Image Studio">
<meta property="og:description"
content="Professional grade image editing in your browser. No uploads required for basic edits. AI background removal, smart resizing, and premium filters.">
<meta property="og:image" content="https://altkriz.github.io/editx/editorx_banner.png">
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://altkriz.github.io/editx/">
<meta property="twitter:title" content="EditX · Kriztech | AI-Powered Image Studio">
<meta property="twitter:image" content="https://altkriz.github.io/editx/editorx_banner.png">
<!-- Favicon - Enhanced with multiple formats for better browser support -->
<link rel="icon" type="image/png" sizes="32x32" href="https://altkriz.github.io/editx/favicon.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://altkriz.github.io/editx/favicon.png">
<link rel="shortcut icon" href="https://altkriz.github.io/editx/favicon.png">
<link rel="apple-touch-icon" href="https://altkriz.github.io/editx/favicon.png">
<link rel="icon" href="https://altkriz.github.io/editx/favicon.png" type="image/png">
<!-- Fallback favicon using emoji in case image doesn't load -->
<link rel="manifest" href="https://altkriz.github.io/editx/manifest.json">
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/face_mesh.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation/selfie_segmentation.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- ... style ... -->
<style>
/* ... existing styles ... */
.layer-item {
background: rgba(255, 255, 255, 0.05);
padding: 0.8rem;
border-radius: 0.5rem;
border: 1px solid var(--card-border);
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.5rem;
}
.layer-item.active {
border-color: var(--accent);
background: rgba(95, 125, 255, 0.1);
}
:root {
--bg-body-dark: radial-gradient(circle at 20% 30%, #0b0f1c, #03050b);
--card-bg-dark: rgba(18, 22, 40, 0.85);
--card-border-dark: rgba(255, 255, 255, 0.08);
--text-main-dark: #fff;
--text-muted-dark: #9da9d0;
--input-bg-dark: #1f2747;
--input-border-dark: #2f3b68;
--bg-body-light: radial-gradient(circle at 20% 30%, #f0f4f8, #d9e2ec);
--card-bg-light: rgba(255, 255, 255, 0.9);
--card-border-light: rgba(0, 0, 0, 0.08);
--text-main-light: #1a202c;
--text-muted-light: #5d6883;
--input-bg-light: #e2e8f0;
--input-border-light: #cbd5e0;
--bg-body: var(--bg-body-dark);
--card-bg: var(--card-bg-dark);
--card-border: var(--card-border-dark);
--text-main: var(--text-main-dark);
--text-muted: var(--text-muted-dark);
--input-bg: var(--input-bg-dark);
--input-border: var(--input-border-dark);
--glass-blur: blur(25px);
--accent: #5f7dff;
}
body.light-mode {
--bg-body: var(--bg-body-light);
--card-bg: var(--card-bg-light);
--card-border: var(--card-border-light);
--text-main: var(--text-main-light);
--text-muted: var(--text-muted-light);
--input-bg: var(--input-bg-light);
--input-border: var(--input-border-light);
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Inter', system-ui, sans-serif;
}
body {
background: var(--bg-body);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 1.5rem;
color: var(--text-main);
transition: background 0.5s ease;
}
.editor-card {
max-width: 1400px;
width: 100%;
max-height: 95vh;
background: var(--card-bg);
-webkit-backdrop-filter: var(--glass-blur);
backdrop-filter: var(--glass-blur);
border: 1px solid var(--card-border);
border-radius: 2rem;
padding: 1.5rem;
box-shadow: 0 40px 80px - 20px rgba(0, 0, 0, 0.5);
display: flex;
flex-direction: column;
gap: 1rem;
position: relative;
overflow: hidden;
}
/* Drag Drop Overlay */
.drag-overlay {
position: absolute;
inset: 0;
z-index: 50;
background: rgba(95, 125, 255, 0.15);
-webkit-backdrop-filter: blur(4px);
backdrop-filter: blur(4px);
border: 2px dashed var(--accent);
border-radius: 2rem;
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
color: var(--accent);
font-weight: bold;
opacity: 0;
pointer-events: none;
transition: 0.2s;
}
.drag-active.drag-overlay {
opacity: 1;
pointer-events: all;
}
.kriztech-header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 1rem;
border-bottom: 1px solid var(--card-border);
}
.logo-glow {
font-size: 1.8rem;
font-weight: 800;
background: linear-gradient(135deg, #fff, #aebaff);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
filter: drop-shadow(0 0 15px rgba(95, 125, 255, 0.4));
}
body.light-mode .logo-glow {
background: linear-gradient(135deg, #3f5ae0, #2638a8);
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
filter: none;
}
/* Layout Grid */
.main-layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 320px;
gap: 1.5rem;
flex: 1;
min-height: 0;
overflow: hidden;
}
@media(max-width: 900px) {
.main-layout {
grid-template-columns: 1fr;
overflow-y: auto;
}
}
/* Left Side: Toolbar + Canvas */
.viewport-col {
display: flex;
flex-direction: column;
gap: 1rem;
min-height: 0;
height: 100%;
}
.toolbar {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
align-items: center;
background: var(--input-bg);
padding: 0.5rem;
border-radius: 1rem;
border: 1px solid var(--card-border);
width: fit-content;
}
.icon-btn {
width: 38px;
height: 38px;
border-radius: 0.8rem;
border: none;
background: transparent;
color: var(--text-muted);
cursor: pointer;
transition: 0.2s;
display: flex;
align-items: center;
justify-content: center;
}
.icon-btn:hover {
background: var(--card-border);
color: var(--text-main);
}
.icon-btn.active {
background: var(--accent);
color: white;
}
.icon-btn:disabled {
opacity: 0.4;
cursor: not-allowed;
}
.canvas-container {
flex-grow: 1;
background: #0c0e14;
border-radius: 1.5rem;
overflow: hidden;
position: relative;
border: 1px solid var(--card-border);
display: flex;
align-items: center;
justify-content: center;
background-image: radial-gradient(var(--card-border) 1px, transparent 1px);
background-size: 20px 20px;
cursor: grab;
width: 100%;
height: 100%;
}
.canvas-container:active {
cursor: grabbing;
}
body.light-mode.canvas-container {
background-color: #f8fafc;
}
canvas {
transform-origin: center;
box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
max-width: none;
/* Handled by transform */
}
.zoom-controls {
position: absolute;
bottom: 1rem;
right: 1rem;
background: rgba(0, 0, 0, 0.6);
-webkit-backdrop-filter: blur(4px);
backdrop-filter: blur(4px);
padding: 0.4rem;
border-radius: 2rem;
display: flex;
gap: 0.5rem;
border: 1px solid rgba(255, 255, 255, 0.1);
}
/* Right Side: Tabbed Controls */
.controls-col {
display: flex;
flex-direction: column;
background: var(--input-bg);
border-radius: 1.5rem;
border: 1px solid var(--card-border);
overflow: hidden;
height: 100%;
}
.tabs-nav {
display: flex;
overflow-x: auto;
flex-shrink: 0;
border-bottom: 1px solid var(--card-border);
background: rgba(0, 0, 0, 0.1);
}
.tab-btn {
flex: 1;
padding: 1rem 0.5rem;
border: none;
background: transparent;
color: var(--text-muted);
font-weight: 600;
cursor: pointer;
font-size: 0.9rem;
min-width: 80px;
text-align: center;
border-bottom: 2px solid transparent;
}
.tab-btn:hover {
color: var(--text-main);
}
.tab-btn.active {
color: var(--accent);
border-bottom-color: var(--accent);
background: rgba(95, 125, 255, 0.05);
}
.tab-content {
padding: 1.5rem;
display: none;
overflow-y: auto;
height: 100%;
}
.tab-content.active {
display: block;
animation: fadeUp 0.3s ease;
}
@keyframes fadeUp {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* UI Components */
.control-group {
margin-bottom: 2rem;
}
.group-label {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--text-muted);
margin-bottom: 0.8rem;
font-weight: 700;
display: flex;
align-items: center;
gap: 6px;
}
.slider-wrap {
margin-bottom: 1.2rem;
}
.slider-header {
display: flex;
justify-content: space-between;
font-size: 0.85rem;
margin-bottom: 0.4rem;
}
input[type=range] {
width: 100%;
height: 5px;
background: var(--card-bg);
border-radius: 5px;
outline: none;
-webkit-appearance: none;
appearance: none;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 16px;
height: 16px;
border-radius: 50%;
background: var(--accent);
cursor: pointer;
border: 2px solid white;
}
.preset-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 0.8rem;
}
.preset-card {
background: var(--card-bg);
padding: 0.8rem;
border-radius: 0.8rem;
border: 1px solid var(--card-border);
cursor: pointer;
text-align: center;
font-size: 0.9rem;
transition: 0.2s;
}
.preset-card:hover {
border-color: var(--accent);
background: var(--input-border);
}
.tool-btn {
width: 100%;
background: var(--card-bg);
border: 1px solid var(--card-border);
padding: 0.8rem;
border-radius: 0.8rem;
color: var(--text-main);
margin-bottom: 0.5rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
transition: 0.2s;
}
.tool-btn:hover {
background: var(--card-border);
}
.tool-btn.primary {
background: var(--accent);
border-color: var(--accent);
color: white;
}
.tool-btn.primary:hover {
opacity: 0.9;
}
/* Export Modal */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 100;
display: none;
align-items: center;
justify-content: center;
-webkit-backdrop-filter: blur(5px);
backdrop-filter: blur(5px);
}
.modal {
background: #12151e;
padding: 2rem;
border-radius: 2rem;
width: 90%;
max-width: 400px;
border: 1px solid #2f3b68;
box-shadow: 0 50px 100px - 20px rgba(0, 0, 0, 0.7);
}
/* SVG Filter Hidden */
.svg-filters {
position: absolute;
width: 0;
height: 0;
pointer-events: none;
}
</style>
</head>
<body>
<!-- SVG Filters for RGB/Grain -->
<svg class="svg-filters">
<defs>
<filter id="sharpen">
<feConvolveMatrix id="sharpen-matrix" order="3" kernelMatrix="0 0 0 0 1 0 0 0 0" />
</filter>
<filter id="grain">
<feTurbulence type="fractalNoise" baseFrequency="0.80" numOctaves="3" stitchTiles="stitch" />
<feColorMatrix type="saturate" values="0" />
<feComponentTransfer>
<feFuncA type="linear" slope="0.5" />
</feComponentTransfer>
</filter>
</defs>
</svg>
<!-- Export Modal -->
<div class="modal-overlay" id="exportModal">
<div class="modal">
<h2 class="text-xl font-bold text-white mb-4"><i class="fa-solid fa-download mr-2 text-blue-500"></i> Export
Image</h2>
<div class="mb-4">
<label class="text-gray-400 text-sm block mb-2">Format</label>
<div class="flex gap-2">
<button
class="flex-1 p-2 rounded bg-gray-800 border border-gray-700 text-white hover:border-blue-500 hover:text-blue-500 transition fmt-btn active"
data-fmt="image/png">PNG</button>
<button
class="flex-1 p-2 rounded bg-gray-800 border border-gray-700 text-white hover:border-blue-500 hover:text-blue-500 transition fmt-btn"
data-fmt="image/jpeg">JPG</button>
<button
class="flex-1 p-2 rounded bg-gray-800 border border-gray-700 text-white hover:border-blue-500 hover:text-blue-500 transition fmt-btn"
data-fmt="image/webp">WEBP</button>
</div>
</div>
<div class="mb-6">
<div class="flex justify-between mb-1">
<label class="text-gray-400 text-sm">Quality</label>
<span id="qualityVal" class="text-blue-400 text-sm">90%</span>
</div>
<input type="range" id="quality" min="10" max="100" value="90">
</div>
<div class="flex gap-3">
<button class="flex-1 p-3 rounded-xl bg-gray-800 text-white hover:bg-gray-700"
onclick="closeModal()">Cancel</button>
<button
class="flex-1 p-3 rounded-xl bg-blue-600 text-white hover:bg-blue-500 font-bold shadow-lg shadow-blue-900/20"
id="confirmExport">Download</button>
</div>
</div>
</div>
<!-- Main App -->
<div class="editor-card" id="dropZone">
<div class="drag-overlay"><i class="fa-solid fa-cloud-arrow-up mr-3"></i> Drop Image Here</div>
<header class="kriztech-header">
<div class="flex items-center gap-3">
<i class="fa-solid fa-layer-group text-blue-500 text-2xl"></i>
<div>
<h1 class="logo-glow leading-none">EditX <span class="text-lg font-light text-blue-400">Pro
Studio</span></h1>
<p class="text-xs text-gray-500 font-medium tracking-widest pl-1 uppercase">by Kriztech</p>
</div>
</div>
<div class="flex gap-3">
<button class="icon-btn" id="themeToggle" title="Toggle Theme"><i class="fa-solid fa-moon"></i></button>
<button
class="bg-blue-600 hover:bg-blue-500 text-white px-5 py-2 rounded-full font-semibold shadow-lg shadow-blue-500/20 transition flex items-center gap-2"
onclick="openExport()">
<i class="fa-solid fa-download"></i> Export
</button>
</div>
</header>
<div class="main-layout">
<!-- Viewport -->
<div class="viewport-col">
<div class="toolbar">
<label class="icon-btn" title="Open Image">
<i class="fa-regular fa-folder-open"></i>
<input type="file" id="uploadInput" hidden accept="image/*">
</label>
<div class="w-px h-6 bg-gray-700 mx-1"></div>
<button class="icon-btn" id="undoBtn" disabled title="Undo"><i
class="fa-solid fa-rotate-left"></i></button>
<button class="icon-btn" id="redoBtn" disabled title="Redo"><i
class="fa-solid fa-rotate-right"></i></button>
<div class="w-px h-6 bg-gray-700 mx-1"></div>
<button class="icon-btn" id="btnMove" title="Move/Pan" class="active"><i
class="fa-solid fa-up-down-left-right"></i></button>
<button class="icon-btn" id="btnBrush" title="Brush"><i class="fa-solid fa-paintbrush"></i></button>
<div class="w-px h-6 bg-gray-700 mx-1"></div>
<button class="icon-btn text-red-400 hover:text-red-300" onclick="resetAll()" title="Reset"><i
class="fa-solid fa-trash"></i></button>
</div>
<div class="canvas-container" id="canvasWrapper">
<canvas id="canvas"></canvas>
<div class="zoom-controls">
<button class="icon-btn w-8 h-8 rounded-full bg-transparent text-white"
onclick="adjustZoom(-0.1)" title="Zoom Out"><i class="fa-solid fa-minus"></i></button>
<span class="text-xs text-white self-center w-12 text-center" id="zoomVal">100%</span>
<button class="icon-btn w-8 h-8 rounded-full bg-transparent text-white"
onclick="adjustZoom(0.1)" title="Zoom In"><i class="fa-solid fa-plus"></i></button>
<button class="icon-btn w-8 h-8 rounded-full bg-transparent text-white" onclick="fitZoom()"
title="Fit"><i class="fa-solid fa-expand"></i></button>
</div>
</div>
</div>
<!-- Controls Side -->
<div class="controls-col">
<div class="tabs-nav">
<button class="tab-btn active" data-tab="adjust">Adjust</button>
<button class="tab-btn" data-tab="tweak">Tweak</button>
<button class="tab-btn" data-tab="creative">Creative</button>
<button class="tab-btn" data-tab="presets">Presets</button>
<button class="tab-btn" data-tab="ai">AI</button>
</div>
<!-- Adjust Tab -->
<div class="tab-content active" id="adjust">
<div class="control-group">
<div class="group-label"><i class="fa-solid fa-sun"></i> Light</div>
<div class="slider-wrap">
<div class="slider-header"><span>Brightness</span><span id="val_brightness">0</span></div>
<input type="range" data-filter="brightness" min="-100" max="100" value="0"
title="Brightness">
</div>
<div class="slider-wrap">
<div class="slider-header"><span>Contrast</span><span id="val_contrast">0</span></div>
<input type="range" data-filter="contrast" min="-100" max="100" value="0" title="Contrast">
</div>
<div class="slider-wrap">
<div class="slider-header"><span>Saturation</span><span id="val_saturation">0</span></div>
<input type="range" data-filter="saturation" min="-100" max="100" value="0"
title="Saturation">
</div>
</div>
<div class="control-group">
<div class="group-label"><i class="fa-solid fa-crop"></i> Geometry</div>
<div class="grid grid-cols-4 gap-2 mb-4">
<button class="tool-btn" onclick="rotate(-90)" title="Rotate Left"><i
class="fa-solid fa-rotate-left"></i></button>
<button class="tool-btn" onclick="rotate(90)" title="Rotate Right"><i
class="fa-solid fa-rotate-right"></i></button>
<button class="tool-btn" onclick="flip('h')" title="Flip Horizontal"><i
class="fa-solid fa-arrows-left-right"></i></button>
<button class="tool-btn" onclick="flip('v')" title="Flip Vertical"><i
class="fa-solid fa-arrows-up-down"></i></button>
</div>
<div class="flex gap-2 justify-center">
<button
class="py-1 px-3 rounded-full border border-gray-600 text-xs hover:bg-blue-600 hover:text-white"
onclick="crop(1)">Square</button>
<button
class="py-1 px-3 rounded-full border border-gray-600 text-xs hover:bg-blue-600 hover:text-white"
onclick="crop(16/9)">16:9</button>
<button
class="py-1 px-3 rounded-full border border-gray-600 text-xs hover:bg-blue-600 hover:text-white"
onclick="crop(4/3)">4:3</button>
</div>
</div>
</div>
<!-- Tweak Tab (Vignette, Noise, RGB) -->
<div class="tab-content" id="tweak">
<div class="control-group">
<div class="group-label"><i class="fa-solid fa-circle-notch"></i> Effects</div>
<div class="slider-wrap">
<div class="slider-header"><span>Vignette</span><span id="val_vignette">0</span></div>
<input type="range" data-filter="vignette" min="0" max="100" value="0">
</div>
<div class="slider-wrap">
<div class="slider-header"><span>Grain / Noise</span><span id="val_noise">0</span></div>
<input type="range" data-filter="noise" min="0" max="100" value="0">
</div>
<div class="slider-wrap">
<div class="slider-header"><span>Blur</span><span id="val_blur">0</span></div>
<input type="range" data-filter="blur" min="0" max="20" value="0">
</div>
<div class="slider-wrap">
<div class="slider-header"><span>Sharpness</span><span id="val_sharpen">0</span></div>
<input type="range" data-filter="sharpen" min="0" max="100" value="0">
</div>
</div>
<div class="control-group">
<div class="group-label"><i class="fa-solid fa-palette"></i> RGB Balance</div>
<div class="slider-wrap">
<div class="slider-header"><span class="text-red-400">Red Channel</span><span
id="val_red">0</span></div>
<input type="range" data-filter="red" min="-50" max="50" value="0" class="accent-red-500">
</div>
<div class="slider-wrap">
<div class="slider-header"><span class="text-green-400">Green Channel</span><span
id="val_green">0</span></div>
<input type="range" data-filter="green" min="-50" max="50" value="0"
class="accent-green-500">
</div>
<div class="slider-wrap">
<div class="slider-header"><span class="text-blue-400">Blue Channel</span><span
id="val_blue">0</span></div>
<input type="range" data-filter="blue" min="-50" max="50" value="0" class="accent-blue-500">
</div>
</div>
</div>
<!-- Creative Tab (Text, Brush, Overlay) -->
<div class="tab-content" id="creative">
<div class="control-group">
<div class="group-label"><i class="fa-solid fa-font"></i> Text Overlay</div>
<input type="text" id="textInput" placeholder="Enter text..."
class="w-full p-2 bg-gray-900 border border-gray-700 rounded mb-2 text-white">
<div class="flex gap-2 mb-2">
<input type="color" id="textColor" value="#ffffff"
class="h-10 w-10 p-0 border-0 rounded cursor-pointer">
<select id="textFont"
class="flex-1 bg-gray-900 border border-gray-700 rounded text-gray-300 p-2">
<option value="Inter">Inter</option>
<option value="serif">Serif</option>
<option value="cursive">Cursive</option>
<option value="monospace">Mono</option>
</select>
</div>
<div class="slider-wrap">
<div class="slider-header"><span>Size</span><span id="val_textSize">40</span></div>
<input type="range" id="textSize" min="10" max="200" value="40">
</div>
<button class="tool-btn primary" id="addTextBtn"><i class="fa-solid fa-plus"></i> Add
Text</button>
</div>
<div class="control-group">
<div class="group-label"><i class="fa-solid fa-paintbrush"></i> Brush Settings</div>
<div class="flex gap-2 items-center mb-2">
<input type="color" id="brushColor" value="#ffcc00"
class="h-8 w-8 rounded-full border-0 p-0">
<span class="text-xs text-gray-400">Color</span>
</div>
<div class="slider-wrap">
<div class="slider-header"><span>Brush Size</span><span id="val_brushSize">5</span></div>
<input type="range" id="brushSize" min="1" max="50" value="5">
</div>
</div>
<div class="control-group">
<div class="group-label"><i class="fa-regular fa-image"></i> Sticker / Overlay</div>
<button class="tool-btn" onclick="document.getElementById('stickerInput').click()">
<i class="fa-solid fa-upload"></i> Upload Overlay Image
</button>
<input type="file" id="stickerInput" hidden accept="image/*">
</div>
</div>
<!-- Presets Tab -->
<div class="tab-content" id="presets">
<div class="preset-grid">
<div class="preset-card" onclick="applyPreset('vintage')">
<i class="fa-solid fa-compact-disc text-2xl mb-2 text-yellow-500"></i><br>Vintage
</div>
<div class="preset-card" onclick="applyPreset('cinematic')">
<i class="fa-solid fa-film text-2xl mb-2 text-blue-400"></i><br>Cinematic
</div>
<div class="preset-card" onclick="applyPreset('drama')">
<i class="fa-solid fa-circle-half-stroke text-2xl mb-2 text-gray-400"></i><br>B&W Drama
</div>
<div class="preset-card" onclick="applyPreset('warm')">
<i class="fa-solid fa-sun text-2xl mb-2 text-orange-400"></i><br>Warmth
</div>
<div class="preset-card" onclick="applyPreset('cyber')">
<i class="fa-solid fa-bolt text-2xl mb-2 text-purple-400"></i><br>Cyberpunk
</div>
</div>
</div>
<!-- AI Tab -->
<div class="tab-content" id="ai">
<div class="control-group">
<div class="group-label"><i class="fa-solid fa-wand-magic-sparkles"></i> Options</div>
<div class="flex gap-2 mb-4">
<button
class="flex-1 p-2 rounded bg-gray-800 border border-blue-500 text-blue-500 text-sm font-bold ai-opt active"
onclick="setAiMode('transparent')">Transparent</button>
<button
class="flex-1 p-2 rounded bg-gray-800 border border-gray-700 text-gray-400 text-sm font-bold ai-opt"
onclick="setAiMode('color')">Color</button>
</div>
<div id="aiColorPicker" class="hidden mb-4">
<label class="text-xs text-gray-400 mb-1 block">Background Color</label>
<input type="color" id="aiBgColor" value="#ffffff"
class="w-full h-10 rounded cursor-pointer">
</div>
<button class="tool-btn primary py-4" id="removeBgBtn">
<i class="fa-solid fa-eraser"></i> Remove Background
</button>
<p class="text-xs text-center mt-2 text-gray-500">AI processing happens locally.</p>
</div>
<div class="control-group">
<div class="group-label"><i class="fa-regular fa-face-smile-beam"></i> Face Retouch</div>
<div class="slider-wrap">
<div class="slider-header"><span>Skin Smooth</span><span id="val_smooth">0</span></div>
<input type="range" id="faceSmooth" min="0" max="100" value="0">
</div>
<button class="tool-btn primary" id="applyFaceBtn">
<i class="fa-solid fa-sparkles"></i> Apply Beauty Filter
</button>
</div>
</div>
</div>
</div>
</div>
<script>
// --- STATE ---
const state = {
img: null,
filters: { brightness: 0, contrast: 0, saturation: 0, blur: 0, sharpen: 0, vignette: 0, noise: 0, red: 0, green: 0, blue: 0 },
rotation: 0, flipH: 1, flipV: 1,
layers: [], // {id, type, visible, opacity, ... }
strokes: [],
zoom: 1, pan: { x: 0, y: 0 },
activeTool: 'move',
brush: { color: '#ffcc00', size: 5 },
history: [], historyIndex: -1,
aiMode: 'transparent',
cropMode: false,
cropRect: null
};
// --- SHORTCUTS ---
document.addEventListener('keydown', e => {
if (e.ctrlKey && (e.key === 'z' || e.key === 'Z')) {
e.preventDefault(); undo();
}
if (e.ctrlKey && (e.key === 'y' || e.key === 'Y')) {
e.preventDefault(); redo();
}
if (e.key === '[') {
const s = Math.max(1, parseInt(document.getElementById('brushSize').value) - 2);
document.getElementById('brushSize').value = s;
state.brush.size = s;
document.getElementById('val_brushSize').innerText = s;
}
if (e.key === ']') {
const s = Math.min(50, parseInt(document.getElementById('brushSize').value) + 2);
document.getElementById('brushSize').value = s;
state.brush.size = s;
document.getElementById('val_brushSize').innerText = s;
}
});
// --- FACE RETOUCH ---
// Listener moved to init()
async function runFaceAI() {
if (!state.img) return alert("No image found!");
const btn = document.getElementById('applyFaceBtn');
const originalText = btn.innerHTML;
btn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Analyzing...';
btn.disabled = true;
try {
const faceMesh = new FaceMesh({ locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/face_mesh/${file}` });
faceMesh.setOptions({ maxNumFaces: 1, refineLandmarks: true, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
faceMesh.onResults(results => {
if (!results.multiFaceLandmarks || results.multiFaceLandmarks.length === 0) {
alert("No face detected!");
btn.innerHTML = originalText;
btn.disabled = false;
return;
}
// Apply Blur (Smoothing)
saveHistory();
// 1. Draw original to temp canvas
const mCanvas = document.createElement('canvas');
mCanvas.width = state.img.width; mCanvas.height = state.img.height;
const mCtx = mCanvas.getContext('2d');
mCtx.drawImage(state.img, 0, 0);
// 2. Create Face Mask
const maskCanvas = document.createElement('canvas');
maskCanvas.width = mCanvas.width; maskCanvas.height = mCanvas.height;
const maskCtx = maskCanvas.getContext('2d');
maskCtx.fillStyle = 'black';
maskCtx.fillRect(0, 0, maskCanvas.width, maskCanvas.height);
maskCtx.fillStyle = 'white';
const landmarks = results.multiFaceLandmarks[0];
// Draw face hull (simplified for perf-cheek/chin area)
maskCtx.beginPath();
// Roughly face contour points from MediaPipe FaceMesh
const indices = [10, 338, 297, 332, 284, 251, 389, 356, 454, 323, 361, 288, 397, 365, 379, 378, 400, 377, 152, 148, 176, 149, 150, 136, 172, 58, 132, 93, 234, 127, 162, 21, 54, 103, 67, 109];
indices.forEach((id, i) => {
const x = landmarks[id].x * maskCanvas.width;
const y = landmarks[id].y * maskCanvas.height;
if (i === 0) maskCtx.moveTo(x, y);
else maskCtx.lineTo(x, y);
});
maskCtx.closePath();
maskCtx.fill();
maskCtx.filter = 'blur(10px)'; // Feather mask
// 3. Create Blurred Face Skin
const blurCanvas = document.createElement('canvas');
blurCanvas.width = mCanvas.width; blurCanvas.height = mCanvas.height;
const bCtx = blurCanvas.getContext('2d');
bCtx.filter = 'blur(5px)'; // Skin smoothing amount
bCtx.drawImage(state.img, 0, 0);
bCtx.filter = 'none';
// 4. Composite: Draw blurred face ONLY where mask is white
bCtx.globalCompositeOperation = 'destination-in';
bCtx.drawImage(maskCanvas, 0, 0);
// 5. Draw smoothed face on top of original
mCtx.globalCompositeOperation = 'source-over';
mCtx.globalAlpha = 0.6; // Opacity of smoothing
mCtx.drawImage(blurCanvas, 0, 0);
// Done
const newImg = new Image();
newImg.src = mCanvas.toDataURL();
newImg.onload = () => {
state.img = newImg;
render();
saveHistory();
btn.innerHTML = originalText;
btn.disabled = false;
};
});
await faceMesh.send({ image: state.img });
} catch (e) {
alert("Face AI Error: " + e);
btn.innerHTML = originalText;
btn.disabled = false;
}
}
// --- INTERACTIVE CROP (Simplified for V2) ---
// For now, we will add a 'custom crop' tool that just prompts for ratio or uses a visual overlay if time.
// Let's stick to the crop(ratio) functionality but improve it to be safer?
// Actually, let's implement the layer visibility check in render() now.
// --- DOM ---
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const fileInput = document.getElementById('uploadInput');
// ... (Init function remains same)
// --- AI ---
// Listener moved to init()
async function runAI() {
if (!state.img) return alert("Please upload an image first.");
const btn = document.getElementById('removeBgBtn');
const originalText = btn.innerHTML;
btn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Processing...';
btn.disabled = true;
try {
const selfieSegmentation = new SelfieSegmentation({ locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/selfie_segmentation/${file}` });
selfieSegmentation.setOptions({ modelSelection: 1 });
selfieSegmentation.onResults(res => {
const mCanvas = document.createElement('canvas');
mCanvas.width = state.img.width; mCanvas.height = state.img.height;
const mCtx = mCanvas.getContext('2d');
if (state.aiMode === 'color') {
mCtx.fillStyle = document.getElementById('aiBgColor').value;
mCtx.fillRect(0, 0, mCanvas.width, mCanvas.height);
}