From 122001448cdd49ec1d9bcc4c2d68aa34a27e14e7 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Tue, 21 Apr 2026 10:33:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=BE=E7=89=87=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E5=88=9D=E5=A7=8B=E7=89=88=E6=9C=AC=20-=20=E5=90=88?= =?UTF-8?q?=E5=B9=B6=E3=80=81=E5=88=86=E5=89=B2=E3=80=81=E6=8C=96=E5=AD=94?= =?UTF-8?q?=E3=80=81=E5=9C=86=E5=BD=A2=E5=88=87=E5=9B=BE=E3=80=81=E6=96=87?= =?UTF-8?q?=E5=AD=97=E5=9B=BE=E7=89=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 87 +++ templates/index.html | 1194 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1281 insertions(+) create mode 100644 app.py create mode 100644 templates/index.html diff --git a/app.py b/app.py new file mode 100644 index 0000000..e2ec164 --- /dev/null +++ b/app.py @@ -0,0 +1,87 @@ +""" +图片编辑器 - Image Editor +前端图片处理工具:合并、分割、挖孔填充、圆形切图、文字图片等 + +端口: 19018 +""" + +from flask import Flask, render_template, jsonify, request, send_file +from flask_cors import CORS +from pathlib import Path +import base64 +import io +from datetime import datetime +import uuid + +app = Flask(__name__, static_folder='static', static_url_path='/static') +CORS(app) + +# 输出目录 +OUTPUT_DIR = Path(__file__).parent / 'outputs' +OUTPUT_DIR.mkdir(exist_ok=True) + +@app.route('/') +def index(): + """主页""" + return render_template('index.html') + +@app.route('/api/health') +def health(): + """健康检查""" + return jsonify({'status': 'ok', 'time': datetime.now().isoformat()}) + +@app.route('/api/save', methods=['POST']) +def save_image(): + """保存图片""" + data = request.get_json() + image_data = data.get('image', '') + filename = data.get('filename', f'image_{uuid.uuid4().hex[:8]}.png') + + if not image_data: + return jsonify({'error': '无图片数据'}), 400 + + # 解析 base64 + if image_data.startswith('data:image'): + image_data = image_data.split(',', 1)[1] + + # 保存 + image_bytes = base64.b64decode(image_data) + filepath = OUTPUT_DIR / filename + filepath.write_bytes(image_bytes) + + return jsonify({ + 'success': True, + 'filename': filename, + 'path': str(filepath) + }) + +@app.route('/api/download/') +def download_image(filename): + """下载图片""" + filepath = OUTPUT_DIR / filename + if not filepath.exists(): + return jsonify({'error': '文件不存在'}), 404 + + return send_file(filepath, as_attachment=True) + +@app.route('/api/list') +def list_images(): + """列出已保存的图片""" + images = [] + for f in OUTPUT_DIR.glob('*.png'): + images.append({ + 'filename': f.name, + 'size': f.stat().st_size, + 'time': datetime.fromtimestamp(f.stat().st_mtime).strftime('%Y-%m-%d %H:%M:%S') + }) + + return jsonify({'images': sorted(images, key=lambda x: x['time'], reverse=True)}) + +if __name__ == '__main__': + print("=" * 50) + print("图片编辑器 - Image Editor") + print("=" * 50) + print(f"访问地址: http://localhost:19018") + print("=" * 50) + + app.run(host='0.0.0.0', port=19018, debug=True) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..e8d34e0 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,1194 @@ + + + + + + 图片编辑器 - Image Editor + + + + + + +
+
+
+

+ 图片编辑器 +

+
+ + + +
+
+ + +
+ + + + + + + + +
+
+
+ + +
+
+
+ + +
+ +

点击"上传图片"或拖放图片开始编辑

+
+
+ + + +
+ + +
+

操作历史

+
+ 暂无操作 +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file