Last active
July 3, 2017 10:41
-
-
Save NegativeMjark/31d2809c3e076806a26e to your computer and use it in GitHub Desktop.
Identicon Generator Webapp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
from flask import Flask, make_response | |
from io import BytesIO | |
from pydenticon import Generator | |
app = Flask(__name__) | |
foreground = [ | |
"rgb(45,79,255)", | |
"rgb(254,180,44)", | |
"rgb(226,121,234)", | |
"rgb(30,179,253)", | |
"rgb(232,77,65)", | |
"rgb(49,203,115)", | |
"rgb(141,69,170)" | |
] | |
background = "rgb(224,224,224)" | |
size = 5 | |
generator = Generator(size, size, foreground=foreground, background=background) | |
@app.route("/<int:width>/<int:height>/<name>/") | |
def identicon(width, height, name): | |
v_padding = width % size | |
h_padding = height % size | |
top_padding = v_padding // 2 | |
left_padding = h_padding // 2 | |
bottom_padding = v_padding - top_padding | |
right_padding = h_padding - left_padding | |
width -= v_padding | |
height -= h_padding | |
padding = (top_padding, bottom_padding, left_padding, right_padding) | |
identicon = generator.generate(name, width, height, padding=padding) | |
response = make_response(identicon) | |
response.headers["Content-Type"] = "image/png" | |
response.headers["Cache-Control"] = "public, max-age=43200" | |
return response | |
@app.route("/<name>/") | |
def identicon_32(name): | |
return identicon(32, 32, name) | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment