Skip to content

Instantly share code, notes, and snippets.

@akmamun
Created February 13, 2019 12:42
Show Gist options
  • Save akmamun/9ab677536f79b62e7052620b854cb37f to your computer and use it in GitHub Desktop.
Save akmamun/9ab677536f79b62e7052620b854cb37f to your computer and use it in GitHub Desktop.
Base 64 to Image Convert in Python
import os
SAVE_DIR = os.path.dirname(os.path.abspath(__file__))
def base64_to_image(filename):
path = os.path.join(SAVE_DIR, 'images/')
if not os.path.isdir(path):
os.mkdir(path)
data = base64.b64decode(filename)
filename = 'frame' + str(datetime.datetime.now().microsecond) + '.jpg'
destination = "/".join([path, filename])
with open(destination, 'wb') as f:
f.write(data)
return data
# @app.route('/frame/upload/', methods=['GET', 'POST'])
# def upload_image():
# if request.method == "POST":
# file = request.form['images']
# convert_to_image(file)
# return "Successfully", 201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment