This commit is contained in:
@ -1,11 +1,13 @@
|
|||||||
import base64
|
|
||||||
import io
|
import io
|
||||||
|
import random
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
import matplotlib.image as mpimg
|
import matplotlib.image as mpimg
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import numba
|
import numba
|
||||||
|
import pickle
|
||||||
|
import base64
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -43,12 +45,14 @@ def get_encoded_img(arr):
|
|||||||
|
|
||||||
@app.route('/getImage', methods=['GET'])
|
@app.route('/getImage', methods=['GET'])
|
||||||
def get_image():
|
def get_image():
|
||||||
name = request.args.get('name')
|
with open('data_100.pickle', 'rb') as f:
|
||||||
fractal = optimized_mandelbrot(1000, 1000, np.random.randint(2, 251), np.random.uniform(-1, 1), np.random.uniform(-1, 1))
|
images = pickle.load(f)
|
||||||
img = get_encoded_img(fractal)
|
buffered = io.BytesIO()
|
||||||
|
random.choice(images).save(buffered, format="JPEG")
|
||||||
|
img_str = base64.b64encode(buffered.getvalue())
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"code": 0,
|
"code": 0,
|
||||||
"image": img,
|
"image": str(img_str),
|
||||||
"first_time": 1
|
"first_time": 1
|
||||||
})
|
})
|
||||||
|
|
||||||
|
BIN
nft_svc/data_100.pickle
Normal file
BIN
nft_svc/data_100.pickle
Normal file
Binary file not shown.
Reference in New Issue
Block a user