@app.route('/upload', methods=['POST', 'GET']) # 添加路由 def upload(): if request.method == 'POST': f = request.files['file'] basepath = os.path.dirname(file) # 当前文件所在路径 upload_path = os.path.join(basepath, 'static/images', secure_filename(f.filename)) f.save(upload_path) # 使用Opencv转换一下图片格式和名称 img = cv2.imread(upload_path) width=img.shape[1] height=(400/width)*img.shape[0] width=400 img= cv2.resize(img,(int(width), int(height))) filenamesave=str(time.time())+".jpg" cv2.imwrite(os.path.join(basepath, 'static/images', filenamesave), img) dict1={'state':1,'path':filenamesave} return jsonify(dict1) return 'Please use Post'

Flask 图片上传路由函数 - 使用 OpenCV 转换图片格式和名称

原文地址: https://www.cveoy.top/t/topic/otZj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录