-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
23 lines (23 loc) · 825 Bytes
/
Copy pathapp.py
File metadata and controls
23 lines (23 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, request
from PIL import Image
import requests
import io
app = Flask(__name__)
@app.route('/', methods=['POST', 'GET'])
def img2color():
if request.method == 'GET':
image_url = request.args.get('img') # 从查询参数中获取图片链接
elif request.method == 'POST':
image_url = request.form.get('img') # 从请求体中获取图片链接
if not image_url:
return "This is img2color API.Please pass the '?img=' parameter when invoking the img", 200
response = requests.get(image_url)
image = Image.open(io.BytesIO(response.content))
image.thumbnail((100, 100))
main_color = image.getpixel((0, 0))
hex_color = '#%02x%02x%02x' % main_color
return hex_color
if __name__ == '__main__':
app.run()