-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphoto_free_crop.html
More file actions
437 lines (369 loc) · 16.9 KB
/
photo_free_crop.html
File metadata and controls
437 lines (369 loc) · 16.9 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
<!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>Passport Photo Maker</title>
<!-- Cropper.js (Required for cropping) -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.13/cropper.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.5.13/cropper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<style>
:root { --primary: #3b82f6; --bg: #f8fafc; --surface: #ffffff; --border: #e2e8f0; --text: #1e293b; --radius: 12px; }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; margin: 0; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
/* Layout */
.container { max-width: 800px; margin: 0 auto; padding: 20px; box-sizing: border-box; }
.header { text-align: center; margin-bottom: 25px; }
h2 { margin: 0; color: var(--primary); font-size: 24px; }
p { color: #64748b; font-size: 14px; margin-top: 5px; }
/* 1. Upload Box */
.upload-area {
border: 2px dashed var(--primary);
background: #eff6ff;
border-radius: var(--radius);
padding: 30px 20px;
text-align: center;
cursor: pointer;
transition: 0.2s;
margin-bottom: 20px;
user-select: none;
}
.upload-area:active { transform: scale(0.98); }
.upload-icon { font-size: 36px; margin-bottom: 10px; display: block; }
.upload-text { font-weight: 600; color: var(--primary); font-size: 16px; }
.upload-sub { font-size: 12px; color: #94a3b8; margin-top:5px; }
input[type="file"] { display: none; }
/* 2. Editor Section */
/* Added padding-bottom so content isn't hidden behind the fixed button */
.editor-section { display: none; animation: fadeIn 0.4s ease; padding-bottom: 100px; }
.cropper-container-box {
background: #1e293b; /* Dark background for contrast */
border-radius: 8px;
height: 400px; /* Fixed height for editor */
overflow: hidden;
margin-bottom: 20px;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}
img#cropImage { max-width: 100%; display: block; }
/* Controls / Presets */
.controls { background: var(--surface); padding: 15px; border-radius: var(--radius); box-shadow: 0 2px 5px rgba(0,0,0,0.05); margin-bottom: 20px; }
.label { font-weight: 600; font-size: 14px; display: block; margin-bottom: 10px; color: #64748b; }
.preset-row {
display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 10px;
scrollbar-width: none; /* Hide scrollbar Firefox */
}
.preset-row::-webkit-scrollbar { display: none; /* Hide scrollbar Chrome */ }
.preset-btn {
flex: 0 0 auto; padding: 10px 15px;
background: var(--bg); border: 1px solid var(--border);
border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 13px; color: #64748b;
transition: 0.2s;
}
.preset-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
/* New Tool Row (Rotate & Quality) */
.tool-row {
display: flex; gap: 10px; align-items: center; border-top: 1px solid #f1f5f9; padding-top: 15px;
}
.rotate-btn {
background: #f1f5f9; border: 1px solid var(--border); border-radius: 8px;
width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
cursor: pointer; color: var(--text); transition: 0.2s;
}
.rotate-btn:active { background: #e2e8f0; transform: scale(0.96); }
.rotate-icon { width: 20px; height: 20px; }
.quality-select {
flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 8px;
font-size: 14px; background: #f8fafc; outline: none;
}
/* Bottom Fixed Navigation Flow Bar */
.bottom-flow-bar {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(10px);
border-top: 1px solid var(--border);
padding: 15px 20px 20px 20px; /* Extra padding for bottom safety area */
box-sizing: border-box;
box-shadow: 0 -4px 20px rgba(0,0,0,0.05);
z-index: 90;
display: flex;
justify-content: center;
}
.flow-btn {
width: 100%;
max-width: 600px;
padding: 16px;
background: var(--primary);
color: white;
border: none;
border-radius: 16px; /* Smooth rounded corners */
font-size: 16px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
transition: transform 0.2s, box-shadow 0.2s;
}
.flow-btn:active { transform: scale(0.98); box-shadow: 0 2px 6px rgba(59, 130, 246, 0.2); }
/* 3. Result Section */
.result-section {
display: none; text-align: center; animation: slideUp 0.4s ease;
background: var(--surface); padding: 20px; border-radius: var(--radius);
box-shadow: 0 2px 10px rgba(0,0,0,0.05);
margin-bottom: 50px;
}
.result-img-wrapper {
display: inline-block;
padding: 10px;
background: white;
border: 1px solid var(--border);
border-radius: 4px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.result-img { max-width: 100%; max-height: 300px; display: block; }
.btn-secondary {
background: transparent; border: 1px solid #cbd5e1;
color: #64748b; padding: 14px; border-radius: 50px;
font-weight: 600; cursor: pointer; width: 100%; margin-top: 10px;
}
/* Guide Section */
.guide-section {
background: var(--surface);
padding: 20px;
border-radius: var(--radius);
border: 1px solid var(--border);
margin-top: 30px;
box-shadow: 0 2px 5px rgba(0,0,0,0.03);
margin-bottom: 100px; /* Space for bottom bar */
}
.guide-section h3 { margin-top: 0; font-size: 18px; color: var(--text); }
.guide-steps { padding-left: 20px; color: #64748b; font-size: 14px; line-height: 1.6; margin-bottom: 15px; }
.guide-img {
width: 100%;
height: auto;
border-radius: 8px;
border: 1px solid var(--border);
display: block;
}
/* Modals */
.modal-overlay {
position: fixed; top: 0; left: 0; width: 100%; height: 100%;
background: rgba(0,0,0,0.85); backdrop-filter: blur(4px);
display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-overlay.active { display: flex; }
.modal-box {
background: white; width: 90%; max-width: 400px;
border-radius: 16px; padding: 25px; max-height: 85vh;
display: flex; flex-direction: column; text-align: center; position: relative;
}
/* Progress Bar */
.progress-container { width: 100%; margin: 15px 0; }
.progress-track { height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); width: 0%; transition: width 0.2s; }
/* Custom Alert Styles */
.alert-icon { font-size: 40px; margin-bottom: 10px; display: block; }
.alert-btns { display: flex; gap: 10px; margin-top: 20px; justify-content: center; }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes slideUp { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h2>Passport Photo Maker</h2>
<p>Crop and format photos for official documents.</p>
</div>
<!-- 1. Upload Area -->
<div class="upload-area" id="uploadBox" onclick="document.getElementById('fileInput').click()">
<span class="upload-icon">📸</span>
<div class="upload-text">Tap to Select Photo</div>
<div class="upload-sub">Supports JPG, PNG, WEBP</div>
</div>
<input type="file" id="fileInput" accept="image/*" onchange="handleFileSelect(this)">
<!-- 2. Editor Area -->
<div id="editorSection" class="editor-section">
<div class="cropper-container-box">
<img id="cropImage" src="">
</div>
<div class="controls">
<!-- Aspect Ratio Presets -->
<span class="label">Step 1: Select Size</span>
<div class="preset-row">
<button class="preset-btn active" onclick="setRatio(3.5/4.5, this)">Passport (3.5x4.5cm)</button>
<button class="preset-btn" onclick="setRatio(1, this)">Square (2x2" US)</button>
<button class="preset-btn" onclick="setRatio(30/40, this)">30x40mm</button>
<button class="preset-btn" onclick="setRatio(35/45, this)">35x45mm (UK/EU)</button>
<button class="preset-btn" onclick="setRatio(NaN, this)">Free Crop</button>
</div>
<!-- Rotate & Quality Tools -->
<div class="tool-row">
<button class="rotate-btn" onclick="rotateImage()" title="Rotate 90°">
<svg class="rotate-icon" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path></svg>
</button>
<select id="qualitySelect" class="quality-select">
<option value="original" selected>Full Resolution (Original)</option>
<option value="high">High Print (1200px)</option>
<option value="screen">Screen (600px)</option>
</select>
</div>
</div>
<!-- NEW BOTTOM FLOATING BAR -->
<div class="bottom-flow-bar">
<button class="flow-btn" onclick="processImage()">Crop & Process</button>
</div>
</div>
<!-- 3. Result Area -->
<div id="resultSection" class="result-section">
<h3 style="margin: 0 0 15px 0; color: var(--primary);">Ready to Download</h3>
<div class="result-img-wrapper">
<img id="resultImage" class="result-img">
</div>
<button class="flow-btn" onclick="downloadResult()">Download Photo</button>
<button class="btn-secondary" onclick="location.reload()">Start Over</button>
</div>
<!-- How to Use Section -->
<div class="guide-section">
<h3>How to Use</h3>
<ol class="guide-steps">
<li><strong>Upload:</strong> Click the upload box to select a high-quality photo from your gallery.</li>
<li><strong>Select Size:</strong> Choose a preset (e.g., Passport) or use "Free Crop" for custom sizes.</li>
<li><strong>Adjust:</strong> Drag the frame to center your face. Use the rotate button if needed.</li>
<li><strong>Download:</strong> Click "Crop & Process" to get your high-quality image.</li>
</ol>
<img src="https://raw.githubusercontent.com/mrbtool/File-maker/refs/heads/main/Picsart_26-01-29_13-07-46-029.png" alt="Visual Guide" class="guide-img">
</div>
</div>
<!-- Progress Modal -->
<div id="loadingModal" class="modal-overlay">
<div class="modal-box">
<h3 style="margin:0 0 10px 0;">Processing...</h3>
<div class="progress-container">
<div class="progress-track"><div id="pFill" class="progress-fill"></div></div>
</div>
<div style="font-size:12px; color:#94a3b8;">Applying crop...</div>
</div>
</div>
<!-- Custom Alert Modal -->
<div id="alertModal" class="modal-overlay">
<div class="modal-box">
<div class="alert-icon">⚠️</div>
<h3 id="alertTitle" style="margin:0 0 10px 0;">Notice</h3>
<p id="alertMsg" style="color:#64748b; margin:0; font-size:14px; line-height:1.5;"></p>
<div class="alert-btns">
<button class="flow-btn" style="padding: 10px 30px;" onclick="closeAlert()">OK</button>
</div>
</div>
</div>
<script>
let cropper = null;
const imageEl = document.getElementById('cropImage');
const uploadBox = document.getElementById('uploadBox');
const editorSection = document.getElementById('editorSection');
const resultSection = document.getElementById('resultSection');
// --- Custom Alert Logic ---
function showAlert(msg) {
document.getElementById('alertMsg').innerText = msg;
document.getElementById('alertModal').classList.add('active');
}
function closeAlert() {
document.getElementById('alertModal').classList.remove('active');
}
// --- Step 1: Handle File ---
function handleFileSelect(input) {
if (input.files && input.files[0]) {
const file = input.files[0];
if (!file.type.startsWith('image/')) {
showAlert("Please select a valid image file.");
return;
}
const reader = new FileReader();
reader.onload = function(e) {
// Hide Upload, Show Editor
uploadBox.style.display = 'none';
editorSection.style.display = 'block';
// Set Image
imageEl.src = e.target.result;
// Init Cropper
if (cropper) cropper.destroy();
cropper = new Cropper(imageEl, {
aspectRatio: 3.5 / 4.5, // Default
viewMode: 1,
autoCropArea: 0.9,
dragMode: 'move',
toggleDragModeOnDblclick: false,
});
}
reader.readAsDataURL(file);
}
input.value = ''; // Reset
}
// --- Step 2: Editor Controls ---
function setRatio(ratio, btn) {
if (!cropper) return;
cropper.setAspectRatio(ratio);
// Update Buttons
document.querySelectorAll('.preset-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
}
function rotateImage() {
if (!cropper) return;
cropper.rotate(90);
}
// --- Step 3: Process ---
function processImage() {
if (!cropper) return;
// Get Quality Setting
const qualityMode = document.getElementById('qualitySelect').value;
// Define cropping options
let cropOptions = {
imageSmoothingEnabled: true,
imageSmoothingQuality: 'high',
};
if (qualityMode === 'screen') {
cropOptions.width = 600;
} else if (qualityMode === 'high') {
cropOptions.width = 1200;
}
// If 'original', no dimensions passed = full size
// Show Loading
document.getElementById('loadingModal').classList.add('active');
const pFill = document.getElementById('pFill');
pFill.style.width = '0%';
setTimeout(() => { pFill.style.width = '50%'; }, 200);
setTimeout(() => {
// Get Canvas
const canvas = cropper.getCroppedCanvas(cropOptions);
if(!canvas) {
document.getElementById('loadingModal').classList.remove('active');
showAlert("Could not crop image. Please try again.");
return;
}
const resultImg = document.getElementById('resultImage');
// Convert to JPEG at high quality (0.95)
resultImg.src = canvas.toDataURL('image/jpeg', 0.95);
pFill.style.width = '100%';
setTimeout(() => {
document.getElementById('loadingModal').classList.remove('active');
editorSection.style.display = 'none';
resultSection.style.display = 'block';
}, 400);
}, 500);
}
// --- Step 4: Download ---
function downloadResult() {
const imgSrc = document.getElementById('resultImage').src;
if(!imgSrc) return;
fetch(imgSrc)
.then(res => res.blob())
.then(blob => {
const date = new Date().getTime();
saveAs(blob, `Passport_Photo_${date}.jpg`);
});
}
</script>
<script src="tool-ads.js"></script>
</body>
</html>