• 2023.11.13使用flask将图片进行黑白处理(url方式进行传输)


    2023.11.13使用flask将图片进行黑白处理(url方式进行传输)

    和下述文章进行对比,实现效果相同,但是使用url方式更简便。
    2023.11.12使用flask对图片进行黑白处理(base64编码方式传输)
    https://editor.csdn.net/md/?articleId=134370865

    
    
    
        
        
        Image Processor
    
    
        

    Image Processor

    Preview Image

    Preview Image

    Processed Image

    Processed Image
    • 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
    from flask import Flask, render_template, request, jsonify
    from PIL import Image
    
    app = Flask(__name__)
    
    @app.route('/')
    def index():
        return render_template('index.html')
    
    @app.route('/process', methods=['POST'])
    def process():
        if 'file' not in request.files:
            return jsonify({'error': 'No file part'})
    
        file = request.files['file']
        img = Image.open(file)
        bw_img = img.convert('L')  # 转换为黑白图片
        bw_img.save('static/processed_image.jpg')  # 保存处理后的图片
    
        return jsonify({'processed_image': '/static/processed_image.jpg'})
    
    if __name__ == '__main__':
        app.run(debug=True)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
  • 相关阅读:
    asp.net水资源检测系统VS开发sqlserver数据库web结构c#编程Microsoft Visual Studio
    ref和reactive
    用Cmake快速生成vs工程
    Docker Debian安装Docker
    爬虫入门到精通_实战篇12(使用Redis+Flask维护动态Cookies池)
    多位数按键操作(不闪烁)
    JVM性能调优--性能测试
    华为云CDN加速,带你畅游网络
    【Hadoop】HDFS 原理
    如何查看SAP版本及HANA版本?
  • 原文地址:https://blog.csdn.net/leigh_chen/article/details/134296284