NodeJS开发证件照处理工具
免费易用:P360 - 证件照处理工具

更改背景色开发中。
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>P360 - 证件照处理工具</title> <style> body { font-family: 'Microsoft YaHei', sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; background-color: #f5f5f5; } .container { background-color: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); } .form-group { margin-bottom: 15px; } label { display: block; margin-bottom: 5px; font-weight: bold; } input[type="file"], input[type="number"], input[type="color"] { width: 100%; padding: 8px; margin-bottom: 10px; border: 1px solid #ddd; border-radius: 4px; } button { background-color: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } #preview { margin-top: 20px; text-align: center; } #preview img { max-width: 100%; margin-top: 10px; } .loading { display: none; text-align: center; margin: 20px 0; } </style> </head> <body> <div class="container"> <h1>P360 - 证件照处理工具</h1> <form id="uploadForm"> <div class="form-group"> <label for="photo">选择照片:</label> <input type="file" id="photo" name="photo" accept="image/*" required> </div> <div class="form-group"> <label for="width">宽度(像素):</label> <input type="number" id="width" name="width" value="295"> </div> <div class="form-group"> <label for="height">高度(像素):</label> <input type="number" id="height" name="height" value="413"> </div> <div class="form-group"> <label> <input type="checkbox" id="changeBackground" name="changeBackground"> 更改背景颜色 </label> </div> <div class="form-group" id="backgroundColorGroup" style="display: none;"> <label for="backgroundColor">背景颜色:</label> <input type="color" id="backgroundColor" name="backgroundColor" value="#FFFFFF"> </div> <button type="submit">处理照片</button> </form> <div class="loading" id="loading">处理中...</div> <div id="preview"></div> </div> <script> document.getElementById('uploadForm').addEventListener('submit', async (e) => { e.preventDefault(); const formData = new FormData(); const photoFile = document.getElementById('photo').files[0]; const width = document.getElementById('width').value; const height = document.getElementById('height').value; const changeBackground = document.getElementById('changeBackground').checked; const backgroundColor = document.getElementById('backgroundColor').value; formData.append('photo', photoFile); formData.append('width', width); formData.append('height', height); formData.append('changeBackground', changeBackground); if (changeBackground) { formData.append('backgroundColor', backgroundColor); } const loading = document.getElementById('loading'); const preview = document.getElementById('preview'); loading.style.display = 'block'; preview.innerHTML = ''; try { const response = await fetch('/upload', { method: 'POST', body: formData }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.error || '上传失败'); } const data = await response.json(); if (data.success) { preview.innerHTML = ` <h3>处理后的照片:</h3> <img src="/processed/${data.processedImage}" alt="处理后的照片"> `; } else { preview.innerHTML = `<p style="color: red;">处理失败:${data.error}</p>`; } } catch (error) { console.error('上传错误:', error); preview.innerHTML = `<p style="color: red;">上传失败:${error.message}</p>`; } finally { loading.style.display = 'none'; } }); </script> <script> // 添加复选框事件监听器 document.getElementById('changeBackground').addEventListener('change', function() { const backgroundColorGroup = document.getElementById('backgroundColorGroup'); backgroundColorGroup.style.display = this.checked ? 'block' : 'none'; }); </script> </body> </html>
/************************************
ldlchina
QQ:3110615
************************************/
浙公网安备 33010602011771号