Examups commited on
Commit
e0fc0e2
·
verified ·
1 Parent(s): 3d37ff1

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +1452 -19
index.html CHANGED
@@ -1,19 +1,1452 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <!DOCTYPE html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Advanced Image Resizer Tool</title>
8
+ <style>
9
+ :root {
10
+ --primary-color: #3498db;
11
+ --primary-hover: #2980b9;
12
+ --success-color: #27ae60;
13
+ --success-hover: #219653;
14
+ --danger-color: #e74c3c;
15
+ --danger-hover: #c0392b;
16
+ --light-gray: #f5f5f5;
17
+ --medium-gray: #ddd;
18
+ --dark-gray: #7f8c8d;
19
+ --text-color: #2c3e50;
20
+ --white: #ffffff;
21
+ }
22
+
23
+ body {
24
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
25
+ max-width: 1000px;
26
+ margin: 0 auto;
27
+ padding: 20px;
28
+ background-color: var(--light-gray);
29
+ color: var(--text-color);
30
+ line-height: 1.6;
31
+ }
32
+
33
+ h1 {
34
+ text-align: center;
35
+ color: var(--text-color);
36
+ margin-bottom: 30px;
37
+ }
38
+
39
+ .container {
40
+ background-color: var(--white);
41
+ border-radius: 10px;
42
+ padding: 25px;
43
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
44
+ }
45
+
46
+ .upload-area {
47
+ border: 3px dashed var(--primary-color);
48
+ border-radius: 8px;
49
+ padding: 40px;
50
+ text-align: center;
51
+ margin-bottom: 25px;
52
+ cursor: pointer;
53
+ transition: all 0.3s ease;
54
+ position: relative;
55
+ overflow: hidden;
56
+ }
57
+
58
+ .upload-area:hover {
59
+ background-color: rgba(52, 152, 219, 0.05);
60
+ border-color: var(--primary-hover);
61
+ }
62
+
63
+ .upload-area.active {
64
+ background-color: rgba(52, 152, 219, 0.1);
65
+ }
66
+
67
+ .upload-area p {
68
+ margin: 0;
69
+ font-size: 18px;
70
+ color: var(--dark-gray);
71
+ }
72
+
73
+ .upload-area i {
74
+ font-size: 48px;
75
+ color: var(--primary-color);
76
+ margin-bottom: 15px;
77
+ display: block;
78
+ }
79
+
80
+ #fileInput {
81
+ display: none;
82
+ }
83
+
84
+ .controls {
85
+ display: grid;
86
+ grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
87
+ gap: 20px;
88
+ margin-bottom: 25px;
89
+ }
90
+
91
+ .control-group {
92
+ margin-bottom: 15px;
93
+ }
94
+
95
+ .control-group h3 {
96
+ margin-top: 0;
97
+ margin-bottom: 15px;
98
+ font-size: 18px;
99
+ border-bottom: 1px solid var(--medium-gray);
100
+ padding-bottom: 5px;
101
+ }
102
+
103
+ label {
104
+ display: block;
105
+ margin-bottom: 8px;
106
+ font-weight: 600;
107
+ color: var(--text-color);
108
+ }
109
+
110
+ select, input, textarea {
111
+ width: 100%;
112
+ padding: 10px;
113
+ border: 1px solid var(--medium-gray);
114
+ border-radius: 6px;
115
+ font-size: 15px;
116
+ transition: border-color 0.3s;
117
+ }
118
+
119
+ select:focus, input:focus, textarea:focus {
120
+ outline: none;
121
+ border-color: var(--primary-color);
122
+ box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
123
+ }
124
+
125
+ .btn {
126
+ display: inline-block;
127
+ color: white;
128
+ border: none;
129
+ padding: 12px 20px;
130
+ border-radius: 6px;
131
+ cursor: pointer;
132
+ font-size: 16px;
133
+ font-weight: 600;
134
+ transition: all 0.3s;
135
+ text-align: center;
136
+ text-decoration: none;
137
+ }
138
+
139
+ .btn-primary {
140
+ background-color: var(--primary-color);
141
+ }
142
+
143
+ .btn-primary:hover {
144
+ background-color: var(--primary-hover);
145
+ transform: translateY(-2px);
146
+ }
147
+
148
+ .btn-success {
149
+ background-color: var(--success-color);
150
+ }
151
+
152
+ .btn-success:hover {
153
+ background-color: var(--success-hover);
154
+ transform: translateY(-2px);
155
+ }
156
+
157
+ .btn-danger {
158
+ background-color: var(--danger-color);
159
+ }
160
+
161
+ .btn-danger:hover {
162
+ background-color: var(--danger-hover);
163
+ transform: translateY(-2px);
164
+ }
165
+
166
+ .btn-group {
167
+ display: flex;
168
+ gap: 10px;
169
+ margin-bottom: 20px;
170
+ }
171
+
172
+ .preview {
173
+ display: grid;
174
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
175
+ gap: 25px;
176
+ margin-top: 30px;
177
+ }
178
+
179
+ .preview-item {
180
+ background-color: var(--white);
181
+ border-radius: 8px;
182
+ padding: 15px;
183
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
184
+ }
185
+
186
+ .preview-item h3 {
187
+ margin-top: 0;
188
+ color: var(--text-color);
189
+ display: flex;
190
+ justify-content: space-between;
191
+ align-items: center;
192
+ }
193
+
194
+ .preview-img-container {
195
+ position: relative;
196
+ margin-bottom: 15px;
197
+ overflow: hidden;
198
+ border-radius: 6px;
199
+ }
200
+
201
+ .preview-img {
202
+ max-width: 100%;
203
+ height: auto;
204
+ display: block;
205
+ border-radius: 6px;
206
+ transition: transform 0.3s;
207
+ }
208
+
209
+ .preview-img-container:hover .preview-img {
210
+ transform: scale(1.03);
211
+ }
212
+
213
+ .dimensions {
214
+ font-size: 14px;
215
+ color: var(--dark-gray);
216
+ margin-top: 5px;
217
+ }
218
+
219
+ .loading {
220
+ display: none;
221
+ text-align: center;
222
+ margin: 30px 0;
223
+ }
224
+
225
+ .spinner {
226
+ border: 5px solid rgba(0, 0, 0, 0.1);
227
+ border-radius: 50%;
228
+ border-top: 5px solid var(--primary-color);
229
+ width: 50px;
230
+ height: 50px;
231
+ animation: spin 1s linear infinite;
232
+ margin: 0 auto 15px;
233
+ }
234
+
235
+ @keyframes spin {
236
+ 0% { transform: rotate(0deg); }
237
+ 100% { transform: rotate(360deg); }
238
+ }
239
+
240
+ .progress-container {
241
+ width: 100%;
242
+ background-color: #f1f1f1;
243
+ border-radius: 5px;
244
+ margin: 15px 0;
245
+ display: none;
246
+ }
247
+
248
+ .progress-bar {
249
+ height: 10px;
250
+ background-color: var(--primary-color);
251
+ border-radius: 5px;
252
+ width: 0%;
253
+ transition: width 0.3s;
254
+ }
255
+
256
+ .quality-slider {
257
+ width: 100%;
258
+ margin: 15px 0;
259
+ }
260
+
261
+ .preset-buttons {
262
+ display: flex;
263
+ flex-wrap: wrap;
264
+ gap: 8px;
265
+ margin-bottom: 15px;
266
+ }
267
+
268
+ .preset-btn {
269
+ padding: 5px 10px;
270
+ background-color: var(--light-gray);
271
+ border: 1px solid var(--medium-gray);
272
+ border-radius: 4px;
273
+ cursor: pointer;
274
+ font-size: 13px;
275
+ transition: all 0.2s;
276
+ }
277
+
278
+ .preset-btn:hover {
279
+ background-color: var(--medium-gray);
280
+ }
281
+
282
+ .preset-btn.active {
283
+ background-color: var(--primary-color);
284
+ color: white;
285
+ border-color: var(--primary-hover);
286
+ }
287
+
288
+ .tooltip {
289
+ position: relative;
290
+ display: inline-block;
291
+ margin-left: 5px;
292
+ cursor: help;
293
+ }
294
+
295
+ .tooltip .tooltiptext {
296
+ visibility: hidden;
297
+ width: 200px;
298
+ background-color: #333;
299
+ color: #fff;
300
+ text-align: center;
301
+ border-radius: 6px;
302
+ padding: 5px;
303
+ position: absolute;
304
+ z-index: 1;
305
+ bottom: 125%;
306
+ left: 50%;
307
+ transform: translateX(-50%);
308
+ opacity: 0;
309
+ transition: opacity 0.3s;
310
+ font-size: 13px;
311
+ font-weight: normal;
312
+ }
313
+
314
+ .tooltip:hover .tooltiptext {
315
+ visibility: visible;
316
+ opacity: 1;
317
+ }
318
+
319
+ .advanced-options {
320
+ margin-top: 20px;
321
+ padding: 15px;
322
+ background-color: rgba(52, 152, 219, 0.05);
323
+ border-radius: 6px;
324
+ border-left: 4px solid var(--primary-color);
325
+ }
326
+
327
+ .toggle-advanced {
328
+ background: none;
329
+ border: none;
330
+ color: var(--primary-color);
331
+ cursor: pointer;
332
+ font-weight: 600;
333
+ display: flex;
334
+ align-items: center;
335
+ gap: 5px;
336
+ padding: 5px 0;
337
+ }
338
+
339
+ .toggle-advanced i {
340
+ transition: transform 0.3s;
341
+ }
342
+
343
+ .toggle-advanced.collapsed i {
344
+ transform: rotate(-90deg);
345
+ }
346
+
347
+ @media (max-width: 768px) {
348
+ .controls {
349
+ grid-template-columns: 1fr;
350
+ }
351
+
352
+ .preview {
353
+ grid-template-columns: 1fr;
354
+ }
355
+
356
+ .btn-group {
357
+ flex-direction: column;
358
+ }
359
+ }
360
+ </style>
361
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
362
+ </head>
363
+ <body>
364
+ <div class="container">
365
+ <h1><i class="fas fa-expand-alt"></i> Advanced Image Resizer Tool</h1>
366
+
367
+ <div class="upload-area" id="uploadArea">
368
+ <i class="fas fa-cloud-upload-alt"></i>
369
+ <p>Drag & drop your image here or click to browse</p>
370
+ <input type="file" id="fileInput" accept="image/*">
371
+ </div>
372
+
373
+ <div class="btn-group">
374
+ <button id="resizeBtn" class="btn btn-primary" disabled>
375
+ <i class="fas fa-crop-alt"></i> Resize Image
376
+ </button>
377
+ <button id="resetBtn" class="btn btn-danger" disabled>
378
+ <i class="fas fa-redo"></i> Reset
379
+ </button>
380
+ </div>
381
+
382
+ <div class="progress-container" id="progressContainer">
383
+ <div class="progress-bar" id="progressBar"></div>
384
+ </div>
385
+
386
+ <div class="loading" id="loading">
387
+ <div class="spinner"></div>
388
+ <p>Processing your image...</p>
389
+ </div>
390
+
391
+ <div class="controls">
392
+ <div class="control-group">
393
+ <h3><i class="fas fa-arrows-alt-h"></i> Dimensions</h3>
394
+
395
+ <label for="aspectRatio">Aspect Ratio:</label>
396
+ <select id="aspectRatio">
397
+ <option value="original">Original</option>
398
+ <option value="1:1">1:1 (Square)</option>
399
+ <option value="16:9">16:9 (Widescreen)</option>
400
+ <option value="4:3">4:3 (Standard)</option>
401
+ <option value="9:16">9:16 (Portrait)</option>
402
+ <option value="custom">Custom Ratio</option>
403
+ <option value="specific">Specific Dimensions</option>
404
+ </select>
405
+
406
+ <div id="customRatioGroup" style="display: none; margin-top: 10px;">
407
+ <label for="customRatio">Custom Ratio (width:height):</label>
408
+ <input type="text" id="customRatio" placeholder="e.g. 3:2">
409
+ </div>
410
+
411
+ <div id="specificDimensionsGroup" style="display: none; margin-top: 10px;">
412
+ <label for="specificWidth">Width (px):</label>
413
+ <input type="number" id="specificWidth" min="1" placeholder="Width">
414
+
415
+ <label for="specificHeight" style="margin-top: 10px;">Height (px):</label>
416
+ <input type="number" id="specificHeight" min="1" placeholder="Height">
417
+
418
+ <label style="margin-top: 10px; display: block;">
419
+ <input type="checkbox" id="lockAspect" checked>
420
+ Lock aspect ratio
421
+ </label>
422
+ </div>
423
+
424
+ <div class="preset-buttons" id="sizePresets">
425
+ <div class="preset-btn" data-width="1920" data-height="1080">HD (1920×1080)</div>
426
+ <div class="preset-btn" data-width="1280" data-height="720">HD (1280×720)</div>
427
+ <div class="preset-btn" data-width="1080" data-height="1080">Square (1080×1080)</div>
428
+ <div class="preset-btn" data-width="800" data-height="600">800×600</div>
429
+ <div class="preset-btn" data-width="640" data-height="480">640×480</div>
430
+ <div class="preset-btn" data-width="400" data-height="400">400×400</div>
431
+ </div>
432
+ </div>
433
+
434
+ <div class="control-group">
435
+ <h3><i class="fas fa-sliders-h"></i> Resize Options</h3>
436
+
437
+ <label for="resizeMethod">Resize Method:</label>
438
+ <select id="resizeMethod">
439
+ <option value="cover">Cover (Crop to fit)</option>
440
+ <option value="contain">Contain (Fit inside, add padding)</option>
441
+ <option value="stretch">Stretch (Distort to fit)</option>
442
+ <option value="fill">Fill (Extend edges)</option>
443
+ </select>
444
+
445
+ <label for="backgroundColor" style="margin-top: 15px;">Background Color:</label>
446
+ <input type="color" id="backgroundColor" value="#ffffff">
447
+
448
+ <label for="imageQuality" style="margin-top: 15px;">Image Quality (JPEG):</label>
449
+ <input type="range" id="imageQuality" min="10" max="100" value="85" class="quality-slider">
450
+ <div style="display: flex; justify-content: space-between;">
451
+ <span>10%</span>
452
+ <span id="qualityValue">85%</span>
453
+ <span>100%</span>
454
+ </div>
455
+
456
+ <label for="outputFormat" style="margin-top: 15px;">Output Format:</label>
457
+ <select id="outputFormat">
458
+ <option value="original">Original Format</option>
459
+ <option value="png">PNG (Lossless)</option>
460
+ <option value="jpeg">JPEG (Compressed)</option>
461
+ <option value="webp">WebP (Modern)</option>
462
+ </select>
463
+ </div>
464
+
465
+ <div class="control-group">
466
+ <h3><i class="fas fa-magic"></i> Enhancements</h3>
467
+
468
+ <label for="brightness">Brightness:</label>
469
+ <input type="range" id="brightness" min="-100" max="100" value="0" class="quality-slider">
470
+
471
+ <label for="contrast" style="margin-top: 15px;">Contrast:</label>
472
+ <input type="range" id="contrast" min="-100" max="100" value="0" class="quality-slider">
473
+
474
+ <label for="saturation" style="margin-top: 15px;">Saturation:</label>
475
+ <input type="range" id="saturation" min="-100" max="100" value="0" class="quality-slider">
476
+
477
+ <label for="sharpness" style="margin-top: 15px;">Sharpness:</label>
478
+ <input type="range" id="sharpness" min="0" max="100" value="0" class="quality-slider">
479
+
480
+ <label for="rotation" style="margin-top: 15px;">Rotation:</label>
481
+ <select id="rotation">
482
+ <option value="0">0°</option>
483
+ <option value="90">90°</option>
484
+ <option value="180">180°</option>
485
+ <option value="270">270°</option>
486
+ <option value="custom">Custom Angle</option>
487
+ </select>
488
+
489
+ <div id="customRotationGroup" style="display: none; margin-top: 10px;">
490
+ <label for="customRotation">Custom Rotation Angle (degrees):</label>
491
+ <input type="number" id="customRotation" min="-360" max="360" value="0">
492
+ </div>
493
+ </div>
494
+ </div>
495
+
496
+ <button class="toggle-advanced" id="toggleAdvanced">
497
+ <i class="fas fa-chevron-down"></i> Advanced Options
498
+ </button>
499
+
500
+ <div class="advanced-options" id="advancedOptions">
501
+ <div class="control-group">
502
+ <label for="blurRadius">Blur Radius:</label>
503
+ <input type="range" id="blurRadius" min="0" max="20" value="0" class="quality-slider">
504
+
505
+ <label for="grayscale" style="margin-top: 15px;">
506
+ <input type="checkbox" id="grayscale"> Convert to Grayscale
507
+ </label>
508
+
509
+ <label for="sepia" style="margin-top: 15px;">
510
+ <input type="checkbox" id="sepia"> Apply Sepia Effect
511
+ </label>
512
+
513
+ <label for="invert" style="margin-top: 15px;">
514
+ <input type="checkbox" id="invert"> Invert Colors
515
+ </label>
516
+
517
+ <label for="border" style="margin-top: 15px;">
518
+ <input type="checkbox" id="addBorder"> Add Border
519
+ </label>
520
+
521
+ <div id="borderOptions" style="display: none; margin-top: 10px;">
522
+ <label for="borderColor">Border Color:</label>
523
+ <input type="color" id="borderColor" value="#000000">
524
+
525
+ <label for="borderWidth" style="margin-top: 10px;">Border Width (px):</label>
526
+ <input type="number" id="borderWidth" min="1" value="5">
527
+
528
+ <label for="borderType" style="margin-top: 10px;">Border Type:</label>
529
+ <select id="borderType">
530
+ <option value="solid">Solid</option>
531
+ <option value="dashed">Dashed</option>
532
+ <option value="dotted">Dotted</option>
533
+ </select>
534
+ </div>
535
+
536
+ <label for="watermark" style="margin-top: 15px;">
537
+ <input type="checkbox" id="addWatermark"> Add Watermark
538
+ </label>
539
+
540
+ <div id="watermarkOptions" style="display: none; margin-top: 10px;">
541
+ <label for="watermarkText">Watermark Text:</label>
542
+ <input type="text" id="watermarkText" placeholder="Your watermark text">
543
+
544
+ <label for="watermarkColor" style="margin-top: 10px;">Text Color:</label>
545
+ <input type="color" id="watermarkColor" value="#ffffff">
546
+
547
+ <label for="watermarkOpacity" style="margin-top: 10px;">Opacity:</label>
548
+ <input type="range" id="watermarkOpacity" min="10" max="100" value="50" class="quality-slider">
549
+
550
+ <label for="watermarkPosition" style="margin-top: 10px;">Position:</label>
551
+ <select id="watermarkPosition">
552
+ <option value="bottom-right">Bottom Right</option>
553
+ <option value="bottom-left">Bottom Left</option>
554
+ <option value="top-right">Top Right</option>
555
+ <option value="top-left">Top Left</option>
556
+ <option value="center">Center</option>
557
+ </select>
558
+
559
+ <label for="watermarkSize" style="margin-top: 10px;">Size:</label>
560
+ <select id="watermarkSize">
561
+ <option value="small">Small</option>
562
+ <option value="medium">Medium</option>
563
+ <option value="large">Large</option>
564
+ </select>
565
+ </div>
566
+ </div>
567
+ </div>
568
+
569
+ <div class="preview" id="previewContainer" style="display: none;">
570
+ <div class="preview-item">
571
+ <h3>Original Image <span class="dimensions" id="originalDimensions"></span></h3>
572
+ <div class="preview-img-container">
573
+ <img id="originalPreview" class="preview-img">
574
+ </div>
575
+ </div>
576
+ <div class="preview-item">
577
+ <h3>Resized Image <span class="dimensions" id="resizedDimensions"></span></h3>
578
+ <div class="preview-img-container">
579
+ <img id="resizedPreview" class="preview-img">
580
+ </div>
581
+ <div style="display: flex; gap: 10px; margin-top: 15px;">
582
+ <a href="#" id="downloadBtn" class="btn btn-success">
583
+ <i class="fas fa-download"></i> Download
584
+ </a>
585
+ <button id="copyBtn" class="btn btn-primary">
586
+ <i class="fas fa-copy"></i> Copy to Clipboard
587
+ </button>
588
+ </div>
589
+ <div id="fileSizeInfo" style="margin-top: 10px; font-size: 14px; color: var(--dark-gray);"></div>
590
+ </div>
591
+ </div>
592
+ </div>
593
+
594
+ <script>
595
+ document.addEventListener('DOMContentLoaded', function() {
596
+ // DOM Elements
597
+ const fileInput = document.getElementById('fileInput');
598
+ const uploadArea = document.getElementById('uploadArea');
599
+ const aspectRatioSelect = document.getElementById('aspectRatio');
600
+ const customRatioGroup = document.getElementById('customRatioGroup');
601
+ const customRatioInput = document.getElementById('customRatio');
602
+ const specificDimensionsGroup = document.getElementById('specificDimensionsGroup');
603
+ const specificWidthInput = document.getElementById('specificWidth');
604
+ const specificHeightInput = document.getElementById('specificHeight');
605
+ const lockAspectCheckbox = document.getElementById('lockAspect');
606
+ const resizeMethodSelect = document.getElementById('resizeMethod');
607
+ const backgroundColorInput = document.getElementById('backgroundColor');
608
+ const outputFormatSelect = document.getElementById('outputFormat');
609
+ const imageQualityInput = document.getElementById('imageQuality');
610
+ const qualityValue = document.getElementById('qualityValue');
611
+ const brightnessInput = document.getElementById('brightness');
612
+ const contrastInput = document.getElementById('contrast');
613
+ const saturationInput = document.getElementById('saturation');
614
+ const sharpnessInput = document.getElementById('sharpness');
615
+ const rotationSelect = document.getElementById('rotation');
616
+ const customRotationGroup = document.getElementById('customRotationGroup');
617
+ const customRotationInput = document.getElementById('customRotation');
618
+ const blurRadiusInput = document.getElementById('blurRadius');
619
+ const grayscaleCheckbox = document.getElementById('grayscale');
620
+ const sepiaCheckbox = document.getElementById('sepia');
621
+ const invertCheckbox = document.getElementById('invert');
622
+ const addBorderCheckbox = document.getElementById('addBorder');
623
+ const borderOptions = document.getElementById('borderOptions');
624
+ const borderColorInput = document.getElementById('borderColor');
625
+ const borderWidthInput = document.getElementById('borderWidth');
626
+ const borderTypeSelect = document.getElementById('borderType');
627
+ const addWatermarkCheckbox = document.getElementById('addWatermark');
628
+ const watermarkOptions = document.getElementById('watermarkOptions');
629
+ const watermarkTextInput = document.getElementById('watermarkText');
630
+ const watermarkColorInput = document.getElementById('watermarkColor');
631
+ const watermarkOpacityInput = document.getElementById('watermarkOpacity');
632
+ const watermarkPositionSelect = document.getElementById('watermarkPosition');
633
+ const watermarkSizeSelect = document.getElementById('watermarkSize');
634
+ const resizeBtn = document.getElementById('resizeBtn');
635
+ const resetBtn = document.getElementById('resetBtn');
636
+ const loadingDiv = document.getElementById('loading');
637
+ const progressContainer = document.getElementById('progressContainer');
638
+ const progressBar = document.getElementById('progressBar');
639
+ const previewContainer = document.getElementById('previewContainer');
640
+ const originalPreview = document.getElementById('originalPreview');
641
+ const resizedPreview = document.getElementById('resizedPreview');
642
+ const originalDimensions = document.getElementById('originalDimensions');
643
+ const resizedDimensions = document.getElementById('resizedDimensions');
644
+ const downloadBtn = document.getElementById('downloadBtn');
645
+ const copyBtn = document.getElementById('copyBtn');
646
+ const fileSizeInfo = document.getElementById('fileSizeInfo');
647
+ const sizePresets = document.getElementById('sizePresets');
648
+ const toggleAdvancedBtn = document.getElementById('toggleAdvanced');
649
+ const advancedOptions = document.getElementById('advancedOptions');
650
+
651
+ // Variables
652
+ let originalImage = null;
653
+ let originalWidth = 0;
654
+ let originalHeight = 0;
655
+ let originalAspectRatio = 0;
656
+ let processing = false;
657
+
658
+ // Event Listeners
659
+ fileInput.addEventListener('change', handleFileSelect);
660
+ uploadArea.addEventListener('click', () => fileInput.click());
661
+ uploadArea.addEventListener('dragover', handleDragOver);
662
+ uploadArea.addEventListener('dragleave', handleDragLeave);
663
+ uploadArea.addEventListener('drop', handleDrop);
664
+ aspectRatioSelect.addEventListener('change', handleAspectRatioChange);
665
+ customRatioInput.addEventListener('input', validateCustomRatio);
666
+ specificWidthInput.addEventListener('input', handleSpecificDimensionChange);
667
+ specificHeightInput.addEventListener('input', handleSpecificDimensionChange);
668
+ lockAspectCheckbox.addEventListener('change', handleLockAspectChange);
669
+ imageQualityInput.addEventListener('input', updateQualityValue);
670
+ rotationSelect.addEventListener('change', handleRotationChange);
671
+ addBorderCheckbox.addEventListener('change', toggleBorderOptions);
672
+ addWatermarkCheckbox.addEventListener('change', toggleWatermarkOptions);
673
+ resizeBtn.addEventListener('click', resizeImage);
674
+ resetBtn.addEventListener('click', resetTool);
675
+ downloadBtn.addEventListener('click', downloadImage);
676
+ copyBtn.addEventListener('click', copyToClipboard);
677
+ sizePresets.addEventListener('click', handlePresetClick);
678
+ toggleAdvancedBtn.addEventListener('click', toggleAdvancedOptions);
679
+
680
+ // Initialize
681
+ updateQualityValue();
682
+ toggleAdvancedBtn.classList.add('collapsed');
683
+ advancedOptions.style.display = 'none';
684
+
685
+ // Functions
686
+ function handleFileSelect(e) {
687
+ const file = e.target.files ? e.target.files[0] : e.dataTransfer.files[0];
688
+
689
+ if (!file.type.match('image.*')) {
690
+ alert('Please select an image file (JPEG, PNG, GIF, etc.)');
691
+ return;
692
+ }
693
+
694
+ // Show loading state
695
+ loadingDiv.style.display = 'block';
696
+ progressContainer.style.display = 'block';
697
+ progressBar.style.width = '0%';
698
+ uploadArea.classList.add('active');
699
+
700
+ const reader = new FileReader();
701
+
702
+ reader.onloadstart = function() {
703
+ progressBar.style.width = '10%';
704
+ };
705
+
706
+ reader.onprogress = function(e) {
707
+ if (e.lengthComputable) {
708
+ const percentLoaded = Math.round((e.loaded / e.total) * 90);
709
+ progressBar.style.width = `${10 + percentLoaded}%`;
710
+ }
711
+ };
712
+
713
+ reader.onload = function(e) {
714
+ progressBar.style.width = '100%';
715
+
716
+ originalImage = new Image();
717
+ originalImage.onload = function() {
718
+ originalWidth = originalImage.width;
719
+ originalHeight = originalImage.height;
720
+ originalAspectRatio = originalWidth / originalHeight;
721
+
722
+ originalPreview.src = e.target.result;
723
+ originalDimensions.textContent = `${originalWidth} × ${originalHeight} (${calculateAspectRatio(originalWidth, originalHeight)})`;
724
+
725
+ // Enable controls
726
+ resizeBtn.disabled = false;
727
+ resetBtn.disabled = false;
728
+
729
+ // Show preview
730
+ previewContainer.style.display = 'grid';
731
+
732
+ // Hide loading
733
+ setTimeout(() => {
734
+ loadingDiv.style.display = 'none';
735
+ progressContainer.style.display = 'none';
736
+ uploadArea.classList.remove('active');
737
+ }, 500);
738
+
739
+ // Auto-resize if needed
740
+ if (aspectRatioSelect.value !== 'original') {
741
+ setTimeout(resizeImage, 100);
742
+ }
743
+ };
744
+ originalImage.src = e.target.result;
745
+ };
746
+
747
+ reader.onerror = function() {
748
+ alert('Error reading file. Please try again.');
749
+ loadingDiv.style.display = 'none';
750
+ progressContainer.style.display = 'none';
751
+ uploadArea.classList.remove('active');
752
+ };
753
+
754
+ reader.readAsDataURL(file);
755
+ }
756
+
757
+ function handleDragOver(e) {
758
+ e.preventDefault();
759
+ uploadArea.style.backgroundColor = 'rgba(52, 152, 219, 0.1)';
760
+ uploadArea.style.borderColor = 'var(--primary-hover)';
761
+ }
762
+
763
+ function handleDragLeave() {
764
+ uploadArea.style.backgroundColor = '';
765
+ uploadArea.style.borderColor = 'var(--primary-color)';
766
+ }
767
+
768
+ function handleDrop(e) {
769
+ e.preventDefault();
770
+ uploadArea.style.backgroundColor = '';
771
+ uploadArea.style.borderColor = 'var(--primary-color)';
772
+
773
+ if (e.dataTransfer.files.length) {
774
+ fileInput.files = e.dataTransfer.files;
775
+ handleFileSelect(e);
776
+ }
777
+ }
778
+
779
+ function handleAspectRatioChange() {
780
+ const value = aspectRatioSelect.value;
781
+
782
+ customRatioGroup.style.display = value === 'custom' ? 'block' : 'none';
783
+ specificDimensionsGroup.style.display = value === 'specific' ? 'block' : 'none';
784
+
785
+ if (value === 'specific' && originalImage) {
786
+ specificWidthInput.value = originalWidth;
787
+ specificHeightInput.value = originalHeight;
788
+ }
789
+
790
+ if (originalImage) {
791
+ resizeImage();
792
+ }
793
+ }
794
+
795
+ function validateCustomRatio() {
796
+ const parts = customRatioInput.value.split(':');
797
+ if (parts.length !== 2 || isNaN(parts[0]) || isNaN(parts[1]) || parts[0] <= 0 || parts[1] <= 0) {
798
+ customRatioInput.style.borderColor = 'var(--danger-color)';
799
+ return false;
800
+ } else {
801
+ customRatioInput.style.borderColor = '';
802
+ return true;
803
+ }
804
+ }
805
+
806
+ function handleSpecificDimensionChange(e) {
807
+ if (!lockAspectCheckbox.checked || !originalImage) return;
808
+
809
+ const changedInput = e.target.id;
810
+ if (changedInput === 'specificWidth') {
811
+ specificHeightInput.value = Math.round(specificWidthInput.value / originalAspectRatio);
812
+ } else {
813
+ specificWidthInput.value = Math.round(specificHeightInput.value * originalAspectRatio);
814
+ }
815
+ }
816
+
817
+ function handleLockAspectChange() {
818
+ if (lockAspectCheckbox.checked && originalImage) {
819
+ specificHeightInput.value = Math.round(specificWidthInput.value / originalAspectRatio);
820
+ }
821
+ }
822
+
823
+ function updateQualityValue() {
824
+ qualityValue.textContent = `${imageQualityInput.value}%`;
825
+ }
826
+
827
+ function handleRotationChange() {
828
+ customRotationGroup.style.display = rotationSelect.value === 'custom' ? 'block' : 'none';
829
+ }
830
+
831
+ function toggleBorderOptions() {
832
+ borderOptions.style.display = addBorderCheckbox.checked ? 'block' : 'none';
833
+ }
834
+
835
+ function toggleWatermarkOptions() {
836
+ watermarkOptions.style.display = addWatermarkCheckbox.checked ? 'block' : 'none';
837
+ }
838
+
839
+ function toggleAdvancedOptions() {
840
+ const isCollapsed = toggleAdvancedBtn.classList.contains('collapsed');
841
+
842
+ if (isCollapsed) {
843
+ toggleAdvancedBtn.classList.remove('collapsed');
844
+ advancedOptions.style.display = 'block';
845
+ } else {
846
+ toggleAdvancedBtn.classList.add('collapsed');
847
+ advancedOptions.style.display = 'none';
848
+ }
849
+ }
850
+
851
+ function handlePresetClick(e) {
852
+ if (e.target.classList.contains('preset-btn')) {
853
+ // Remove active class from all buttons
854
+ document.querySelectorAll('.preset-btn').forEach(btn => {
855
+ btn.classList.remove('active');
856
+ });
857
+
858
+ // Add active class to clicked button
859
+ e.target.classList.add('active');
860
+
861
+ // Set aspect ratio to specific dimensions
862
+ aspectRatioSelect.value = 'specific';
863
+ specificDimensionsGroup.style.display = 'block';
864
+
865
+ // Set the dimensions
866
+ const width = parseInt(e.target.dataset.width);
867
+ const height = parseInt(e.target.dataset.height);
868
+ specificWidthInput.value = width;
869
+ specificHeightInput.value = height;
870
+
871
+ // Update lock aspect ratio
872
+ lockAspectCheckbox.checked = false;
873
+
874
+ // Trigger resize if image is loaded
875
+ if (originalImage) {
876
+ resizeImage();
877
+ }
878
+ }
879
+ }
880
+
881
+ function calculateAspectRatio(width, height) {
882
+ const gcd = (a, b) => b === 0 ? a : gcd(b, a % b);
883
+ const divisor = gcd(width, height);
884
+ return `${width / divisor}:${height / divisor}`;
885
+ }
886
+
887
+ function parseAspectRatio(ratioStr) {
888
+ if (ratioStr === 'custom') {
889
+ if (!validateCustomRatio()) return null;
890
+
891
+ const parts = customRatioInput.value.split(':');
892
+ return {
893
+ width: parseFloat(parts[0]),
894
+ height: parseFloat(parts[1])
895
+ };
896
+ } else if (ratioStr === 'specific') {
897
+ return {
898
+ width: parseInt(specificWidthInput.value) || originalWidth,
899
+ height: parseInt(specificHeightInput.value) || originalHeight
900
+ };
901
+ } else if (ratioStr === 'original') {
902
+ return {
903
+ width: originalWidth,
904
+ height: originalHeight
905
+ };
906
+ } else {
907
+ const parts = ratioStr.split(':');
908
+ return {
909
+ width: parseFloat(parts[0]),
910
+ height: parseFloat(parts[1])
911
+ };
912
+ }
913
+ }
914
+
915
+ function resizeImage() {
916
+ if (!originalImage || processing) return;
917
+
918
+ processing = true;
919
+ loadingDiv.style.display = 'block';
920
+ previewContainer.style.display = 'none';
921
+
922
+ // Use setTimeout to allow UI to update
923
+ setTimeout(() => {
924
+ try {
925
+ const targetRatio = parseAspectRatio(aspectRatioSelect.value);
926
+ if (!targetRatio) {
927
+ processing = false;
928
+ loadingDiv.style.display = 'none';
929
+ return;
930
+ }
931
+
932
+ const method = resizeMethodSelect.value;
933
+ const bgColor = backgroundColorInput.value;
934
+ const quality = parseInt(imageQualityInput.value) / 100;
935
+ const outputFormat = outputFormatSelect.value === 'original'
936
+ ? getFileExtension(fileInput.files[0].name)
937
+ : outputFormatSelect.value;
938
+
939
+ // Create canvas
940
+ const canvas = document.createElement('canvas');
941
+ const ctx = canvas.getContext('2d');
942
+
943
+ // Calculate dimensions based on method
944
+ let drawWidth, drawHeight, offsetX = 0, offsetY = 0;
945
+ let canvasWidth = targetRatio.width;
946
+ let canvasHeight = targetRatio.height;
947
+
948
+ // Apply rotation if needed
949
+ let rotationAngle = 0;
950
+ if (rotationSelect.value === 'custom') {
951
+ rotationAngle = parseInt(customRotationInput.value) || 0;
952
+ } else {
953
+ rotationAngle = parseInt(rotationSelect.value) || 0;
954
+ }
955
+
956
+ // Swap dimensions for 90° and 270° rotations
957
+ if (Math.abs(rotationAngle) % 180 === 90) {
958
+ [canvasWidth, canvasHeight] = [canvasHeight, canvasWidth];
959
+ }
960
+
961
+ // Scale dimensions to maintain reasonable size
962
+ const maxDimension = 2000;
963
+ const scaleFactor = Math.min(
964
+ maxDimension / canvasWidth,
965
+ maxDimension / canvasHeight
966
+ );
967
+
968
+ canvas.width = Math.round(canvasWidth * scaleFactor);
969
+ canvas.height = Math.round(canvasHeight * scaleFactor);
970
+
971
+ // Apply background color
972
+ ctx.fillStyle = bgColor;
973
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
974
+
975
+ // Calculate drawing parameters based on resize method
976
+ if (method === 'cover') {
977
+ // Crop to cover the target aspect ratio
978
+ const sourceAspect = originalImage.width / originalImage.height;
979
+ const targetAspect = targetRatio.width / targetRatio.height;
980
+
981
+ let sourceX = 0, sourceY = 0;
982
+ let sourceWidth = originalImage.width;
983
+ let sourceHeight = originalImage.height;
984
+
985
+ if (sourceAspect > targetAspect) {
986
+ // Original is wider than target - crop sides
987
+ sourceWidth = originalImage.height * targetAspect;
988
+ sourceX = (originalImage.width - sourceWidth) / 2;
989
+ } else {
990
+ // Original is taller than target - crop top/bottom
991
+ sourceHeight = originalImage.width / targetAspect;
992
+ sourceY = (originalImage.height - sourceHeight) / 2;
993
+ }
994
+
995
+ // Draw the cropped portion of the original image, scaled to target size
996
+ ctx.drawImage(
997
+ originalImage,
998
+ sourceX, sourceY, sourceWidth, sourceHeight,
999
+ 0, 0, canvas.width, canvas.height
1000
+ );
1001
+ }
1002
+ else if (method === 'contain') {
1003
+ // Fit inside target aspect ratio with padding
1004
+ const sourceAspect = originalImage.width / originalImage.height;
1005
+ const targetAspect = targetRatio.width / targetRatio.height;
1006
+
1007
+ if (sourceAspect > targetAspect) {
1008
+ // Original is wider than target - add padding top/bottom
1009
+ drawWidth = canvas.width;
1010
+ drawHeight = canvas.width / sourceAspect;
1011
+ offsetY = (canvas.height - drawHeight) / 2;
1012
+ } else {
1013
+ // Original is taller than target - add padding sides
1014
+ drawWidth = canvas.height * sourceAspect;
1015
+ drawHeight = canvas.height;
1016
+ offsetX = (canvas.width - drawWidth) / 2;
1017
+ }
1018
+
1019
+ // Draw the original image centered with padding
1020
+ ctx.drawImage(
1021
+ originalImage,
1022
+ offsetX, offsetY, drawWidth, drawHeight
1023
+ );
1024
+ }
1025
+ else if (method === 'stretch') {
1026
+ // Stretch to fit target aspect ratio (distorts image)
1027
+ ctx.drawImage(
1028
+ originalImage,
1029
+ 0, 0, canvas.width, canvas.height
1030
+ );
1031
+ }
1032
+ else if (method === 'fill') {
1033
+ // Fill by extending edges
1034
+ // This is a simplified version - more advanced algorithms exist
1035
+ ctx.drawImage(
1036
+ originalImage,
1037
+ 0, 0, canvas.width, canvas.height
1038
+ );
1039
+ }
1040
+
1041
+ // Apply image enhancements
1042
+ applyImageEffects(ctx, canvas.width, canvas.height);
1043
+
1044
+ // Rotate the image if needed
1045
+ if (rotationAngle !== 0) {
1046
+ rotateImage(canvas, rotationAngle);
1047
+ }
1048
+
1049
+ // Add border if enabled
1050
+ if (addBorderCheckbox.checked) {
1051
+ addBorderToCanvas(canvas, ctx);
1052
+ }
1053
+
1054
+ // Add watermark if enabled
1055
+ if (addWatermarkCheckbox.checked && watermarkTextInput.value) {
1056
+ addWatermarkToCanvas(canvas, ctx);
1057
+ }
1058
+
1059
+ // Get the final image data
1060
+ let mimeType;
1061
+ switch (outputFormat) {
1062
+ case 'png': mimeType = 'image/png'; break;
1063
+ case 'jpeg': mimeType = 'image/jpeg'; break;
1064
+ case 'webp': mimeType = 'image/webp'; break;
1065
+ default: mimeType = fileInput.files[0].type || 'image/png';
1066
+ }
1067
+
1068
+ const imageData = canvas.toDataURL(mimeType, outputFormat === 'jpeg' ? quality : 1);
1069
+
1070
+ // Update the preview
1071
+ resizedPreview.src = imageData;
1072
+ resizedDimensions.textContent = `${canvas.width} × ${canvas.height} (${calculateAspectRatio(canvas.width, canvas.height)})`;
1073
+
1074
+ // Update download button
1075
+ downloadBtn.href = imageData;
1076
+ const extension = outputFormat === 'jpeg' ? 'jpg' : outputFormat;
1077
+ downloadBtn.download = `resized-${fileInput.files[0].name.replace(/\.[^/.]+$/, "")}.${extension}`;
1078
+
1079
+ // Update file size info
1080
+ updateFileSizeInfo(imageData);
1081
+
1082
+ // Show preview
1083
+ previewContainer.style.display = 'grid';
1084
+ } catch (error) {
1085
+ console.error('Error resizing image:', error);
1086
+ alert('An error occurred while processing the image. Please try again.');
1087
+ } finally {
1088
+ loadingDiv.style.display = 'none';
1089
+ processing = false;
1090
+ }
1091
+ }, 100);
1092
+ }
1093
+
1094
+ function applyImageEffects(ctx, width, height) {
1095
+ // Create a temporary canvas for effects
1096
+ const tempCanvas = document.createElement('canvas');
1097
+ tempCanvas.width = width;
1098
+ tempCanvas.height = height;
1099
+ const tempCtx = tempCanvas.getContext('2d');
1100
+
1101
+ // Draw the current canvas content to temp canvas
1102
+ tempCtx.drawImage(ctx.canvas, 0, 0);
1103
+
1104
+ // Get image data
1105
+ const imageData = tempCtx.getImageData(0, 0, width, height);
1106
+ const data = imageData.data;
1107
+
1108
+ // Apply brightness, contrast, saturation
1109
+ const brightness = parseInt(brightnessInput.value) / 100;
1110
+ const contrast = parseInt(contrastInput.value) / 100;
1111
+ const saturation = parseInt(saturationInput.value) / 100;
1112
+ const grayscale = grayscaleCheckbox.checked;
1113
+ const sepia = sepiaCheckbox.checked;
1114
+ const invert = invertCheckbox.checked;
1115
+ const sharpness = parseInt(sharpnessInput.value) / 100;
1116
+ const blurRadius = parseInt(blurRadiusInput.value);
1117
+
1118
+ // Apply pixel-level effects
1119
+ if (brightness !== 0 || contrast !== 0 || saturation !== 0 || grayscale || sepia || invert) {
1120
+ for (let i = 0; i < data.length; i += 4) {
1121
+ let r = data[i];
1122
+ let g = data[i + 1];
1123
+ let b = data[i + 2];
1124
+
1125
+ // Apply brightness
1126
+ if (brightness !== 0) {
1127
+ r = r + (255 * brightness);
1128
+ g = g + (255 * brightness);
1129
+ b = b + (255 * brightness);
1130
+ }
1131
+
1132
+ // Apply contrast
1133
+ if (contrast !== 0) {
1134
+ const factor = (259 * (contrast + 255)) / (255 * (259 - contrast));
1135
+ r = factor * (r - 128) + 128;
1136
+ g = factor * (g - 128) + 128;
1137
+ b = factor * (b - 128) + 128;
1138
+ }
1139
+
1140
+ // Apply saturation
1141
+ if (saturation !== 0) {
1142
+ const gray = 0.2989 * r + 0.5870 * g + 0.1140 * b;
1143
+ r = gray + saturation * (r - gray);
1144
+ g = gray + saturation * (g - gray);
1145
+ b = gray + saturation * (b - gray);
1146
+ }
1147
+
1148
+ // Apply grayscale
1149
+ if (grayscale) {
1150
+ const avg = 0.299 * r + 0.587 * g + 0.114 * b;
1151
+ r = g = b = avg;
1152
+ }
1153
+
1154
+ // Apply sepia
1155
+ if (sepia) {
1156
+ r = Math.min(255, (r * 0.393) + (g * 0.769) + (b * 0.189));
1157
+ g = Math.min(255, (r * 0.349) + (g * 0.686) + (b * 0.168));
1158
+ b = Math.min(255, (r * 0.272) + (g * 0.534) + (b * 0.131));
1159
+ }
1160
+
1161
+ // Apply invert
1162
+ if (invert) {
1163
+ r = 255 - r;
1164
+ g = 255 - g;
1165
+ b = 255 - b;
1166
+ }
1167
+
1168
+ // Clamp values
1169
+ data[i] = Math.max(0, Math.min(255, r));
1170
+ data[i + 1] = Math.max(0, Math.min(255, g));
1171
+ data[i + 2] = Math.max(0, Math.min(255, b));
1172
+ }
1173
+
1174
+ tempCtx.putImageData(imageData, 0, 0);
1175
+ }
1176
+
1177
+ // Apply blur (simplified - for better blur use more advanced methods)
1178
+ if (blurRadius > 0) {
1179
+ tempCtx.filter = `blur(${blurRadius}px)`;
1180
+ tempCtx.drawImage(tempCanvas, 0, 0);
1181
+ tempCtx.filter = 'none';
1182
+ }
1183
+
1184
+ // Apply sharpness (simplified unsharp mask)
1185
+ if (sharpness > 0) {
1186
+ // Create a blurred version
1187
+ const blurCanvas = document.createElement('canvas');
1188
+ blurCanvas.width = width;
1189
+ blurCanvas.height = height;
1190
+ const blurCtx = blurCanvas.getContext('2d');
1191
+ blurCtx.filter = 'blur(1px)';
1192
+ blurCtx.drawImage(tempCanvas, 0, 0);
1193
+ blurCtx.filter = 'none';
1194
+
1195
+ // Subtract blurred from original and add back with strength
1196
+ const amount = sharpness * 2;
1197
+ tempCtx.globalCompositeOperation = 'overlay';
1198
+ tempCtx.globalAlpha = amount;
1199
+ tempCtx.drawImage(blurCanvas, 0, 0);
1200
+ tempCtx.globalCompositeOperation = 'source-over';
1201
+ tempCtx.globalAlpha = 1.0;
1202
+ }
1203
+
1204
+ // Draw the final result back to main canvas
1205
+ ctx.drawImage(tempCanvas, 0, 0);
1206
+ }
1207
+
1208
+ function rotateImage(canvas, angle) {
1209
+ angle = angle % 360;
1210
+ if (angle === 0) return;
1211
+
1212
+ const radians = angle * Math.PI / 180;
1213
+ const sin = Math.abs(Math.sin(radians));
1214
+ const cos = Math.abs(Math.cos(radians));
1215
+
1216
+ const newWidth = Math.floor(canvas.width * cos + canvas.height * sin);
1217
+ const newHeight = Math.floor(canvas.width * sin + canvas.height * cos);
1218
+
1219
+ const tempCanvas = document.createElement('canvas');
1220
+ tempCanvas.width = newWidth;
1221
+ tempCanvas.height = newHeight;
1222
+ const tempCtx = tempCanvas.getContext('2d');
1223
+
1224
+ tempCtx.translate(newWidth / 2, newHeight / 2);
1225
+ tempCtx.rotate(radians);
1226
+ tempCtx.drawImage(canvas, -canvas.width / 2, -canvas.height / 2);
1227
+
1228
+ // Resize the original canvas
1229
+ canvas.width = newWidth;
1230
+ canvas.height = newHeight;
1231
+
1232
+ // Draw the rotated image back
1233
+ const ctx = canvas.getContext('2d');
1234
+ ctx.drawImage(tempCanvas, 0, 0);
1235
+ }
1236
+
1237
+ function addBorderToCanvas(canvas, ctx) {
1238
+ const borderWidth = parseInt(borderWidthInput.value) || 5;
1239
+ const borderColor = borderColorInput.value;
1240
+ const borderType = borderTypeSelect.value;
1241
+
1242
+ // Save the current image
1243
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
1244
+
1245
+ // Clear canvas and draw border
1246
+ ctx.fillStyle = borderColor;
1247
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
1248
+
1249
+ // Draw the image inside the border
1250
+ const innerWidth = canvas.width - (borderWidth * 2);
1251
+ const innerHeight = canvas.height - (borderWidth * 2);
1252
+
1253
+ if (borderType === 'dashed' || borderType === 'dotted') {
1254
+ // For dashed/dotted borders, we need to draw the image first
1255
+ ctx.putImageData(imageData, borderWidth, borderWidth, 0, 0, innerWidth, innerHeight);
1256
+
1257
+ // Then draw the border on top
1258
+ ctx.strokeStyle = borderColor;
1259
+ ctx.lineWidth = borderWidth;
1260
+
1261
+ if (borderType === 'dashed') {
1262
+ ctx.setLineDash([10, 5]);
1263
+ } else {
1264
+ ctx.setLineDash([2, 3]);
1265
+ }
1266
+
1267
+ ctx.strokeRect(borderWidth / 2, borderWidth / 2,
1268
+ canvas.width - borderWidth, canvas.height - borderWidth);
1269
+ ctx.setLineDash([]);
1270
+ } else {
1271
+ // For solid border, just draw the image inside
1272
+ ctx.putImageData(imageData, borderWidth, borderWidth, 0, 0, innerWidth, innerHeight);
1273
+ }
1274
+ }
1275
+
1276
+ function addWatermarkToCanvas(canvas, ctx) {
1277
+ const text = watermarkTextInput.value || '';
1278
+ const color = watermarkColorInput.value;
1279
+ const opacity = parseInt(watermarkOpacityInput.value) / 100;
1280
+ const position = watermarkPositionSelect.value;
1281
+ const size = watermarkSizeSelect.value;
1282
+
1283
+ if (!text) return;
1284
+
1285
+ // Set font size based on selection
1286
+ let fontSize;
1287
+ switch (size) {
1288
+ case 'small': fontSize = canvas.width / 20; break;
1289
+ case 'large': fontSize = canvas.width / 10; break;
1290
+ default: fontSize = canvas.width / 15; // medium
1291
+ }
1292
+
1293
+ ctx.font = `bold ${fontSize}px Arial`;
1294
+ ctx.fillStyle = color;
1295
+ ctx.globalAlpha = opacity;
1296
+ ctx.textAlign = 'center';
1297
+ ctx.textBaseline = 'middle';
1298
+
1299
+ // Calculate position
1300
+ let x, y;
1301
+ const padding = canvas.width / 20;
1302
+
1303
+ switch (position) {
1304
+ case 'top-left':
1305
+ x = padding + ctx.measureText(text).width / 2;
1306
+ y = padding + fontSize / 2;
1307
+ ctx.textAlign = 'left';
1308
+ break;
1309
+ case 'top-right':
1310
+ x = canvas.width - padding - ctx.measureText(text).width / 2;
1311
+ y = padding + fontSize / 2;
1312
+ ctx.textAlign = 'right';
1313
+ break;
1314
+ case 'bottom-left':
1315
+ x = padding + ctx.measureText(text).width / 2;
1316
+ y = canvas.height - padding - fontSize / 2;
1317
+ ctx.textAlign = 'left';
1318
+ break;
1319
+ case 'bottom-right':
1320
+ x = canvas.width - padding - ctx.measureText(text).width / 2;
1321
+ y = canvas.height - padding - fontSize / 2;
1322
+ ctx.textAlign = 'right';
1323
+ break;
1324
+ default: // center
1325
+ x = canvas.width / 2;
1326
+ y = canvas.height / 2;
1327
+ }
1328
+
1329
+ // Add text shadow for better visibility
1330
+ ctx.shadowColor = 'rgba(0, 0, 0, 0.5)';
1331
+ ctx.shadowBlur = 5;
1332
+ ctx.shadowOffsetX = 2;
1333
+ ctx.shadowOffsetY = 2;
1334
+
1335
+ // Draw the text
1336
+ ctx.fillText(text, x, y);
1337
+
1338
+ // Reset context settings
1339
+ ctx.globalAlpha = 1.0;
1340
+ ctx.shadowColor = 'transparent';
1341
+ }
1342
+
1343
+ function updateFileSizeInfo(dataURL) {
1344
+ // Calculate the approximate file size
1345
+ const sizeInBytes = Math.round((dataURL.length * 3) / 4);
1346
+ let sizeText;
1347
+
1348
+ if (sizeInBytes < 1024) {
1349
+ sizeText = `${sizeInBytes} bytes`;
1350
+ } else if (sizeInBytes < 1024 * 1024) {
1351
+ sizeText = `${(sizeInBytes / 1024).toFixed(1)} KB`;
1352
+ } else {
1353
+ sizeText = `${(sizeInBytes / (1024 * 1024)).toFixed(1)} MB`;
1354
+ }
1355
+
1356
+ fileSizeInfo.textContent = `File size: ~${sizeText}`;
1357
+ }
1358
+
1359
+ function getFileExtension(filename) {
1360
+ return filename.split('.').pop().toLowerCase();
1361
+ }
1362
+
1363
+ function downloadImage(e) {
1364
+ if (!resizedPreview.src) {
1365
+ e.preventDefault();
1366
+ alert('No resized image available to download.');
1367
+ }
1368
+ // The actual download is handled by the anchor tag's download attribute
1369
+ }
1370
+
1371
+ async function copyToClipboard() {
1372
+ if (!resizedPreview.src) {
1373
+ alert('No resized image available to copy.');
1374
+ return;
1375
+ }
1376
+
1377
+ try {
1378
+ // Fetch the image data
1379
+ const response = await fetch(resizedPreview.src);
1380
+ const blob = await response.blob();
1381
+
1382
+ // Copy to clipboard
1383
+ await navigator.clipboard.write([
1384
+ new ClipboardItem({
1385
+ [blob.type]: blob
1386
+ })
1387
+ ]);
1388
+
1389
+ alert('Image copied to clipboard!');
1390
+ } catch (error) {
1391
+ console.error('Error copying image:', error);
1392
+ alert('Failed to copy image to clipboard. Your browser may not support this feature.');
1393
+ }
1394
+ }
1395
+
1396
+ function resetTool() {
1397
+ // Reset file input
1398
+ fileInput.value = '';
1399
+
1400
+ // Reset previews
1401
+ originalPreview.src = '';
1402
+ resizedPreview.src = '';
1403
+ originalDimensions.textContent = '';
1404
+ resizedDimensions.textContent = '';
1405
+ fileSizeInfo.textContent = '';
1406
+
1407
+ // Hide preview container
1408
+ previewContainer.style.display = 'none';
1409
+
1410
+ // Reset controls
1411
+ aspectRatioSelect.value = 'original';
1412
+ customRatioGroup.style.display = 'none';
1413
+ specificDimensionsGroup.style.display = 'none';
1414
+ resizeMethodSelect.value = 'cover';
1415
+ backgroundColorInput.value = '#ffffff';
1416
+ outputFormatSelect.value = 'original';
1417
+ imageQualityInput.value = '85';
1418
+ updateQualityValue();
1419
+ brightnessInput.value = '0';
1420
+ contrastInput.value = '0';
1421
+ saturationInput.value = '0';
1422
+ sharpnessInput.value = '0';
1423
+ rotationSelect.value = '0';
1424
+ customRotationGroup.style.display = 'none';
1425
+ blurRadiusInput.value = '0';
1426
+ grayscaleCheckbox.checked = false;
1427
+ sepiaCheckbox.checked = false;
1428
+ invertCheckbox.checked = false;
1429
+ addBorderCheckbox.checked = false;
1430
+ borderOptions.style.display = 'none';
1431
+ addWatermarkCheckbox.checked = false;
1432
+ watermarkOptions.style.display = 'none';
1433
+
1434
+ // Disable buttons
1435
+ resizeBtn.disabled = true;
1436
+ resetBtn.disabled = true;
1437
+
1438
+ // Reset variables
1439
+ originalImage = null;
1440
+ originalWidth = 0;
1441
+ originalHeight = 0;
1442
+ originalAspectRatio = 0;
1443
+
1444
+ // Remove active class from preset buttons
1445
+ document.querySelectorAll('.preset-btn').forEach(btn => {
1446
+ btn.classList.remove('active');
1447
+ });
1448
+ }
1449
+ });
1450
+ </script>
1451
+ </body>
1452
+ </html>