diff --git a/fonts/BebasNeue-Regular.ttf b/fonts/BebasNeue-Regular.ttf new file mode 100644 index 0000000..d2190b5 Binary files /dev/null and b/fonts/BebasNeue-Regular.ttf differ diff --git a/agency_fb.ttf b/fonts/agency_fb.ttf similarity index 100% rename from agency_fb.ttf rename to fonts/agency_fb.ttf diff --git a/server.py b/server.py index 9c93d22..f3301bb 100644 --- a/server.py +++ b/server.py @@ -13,7 +13,7 @@ def headers(): header = [] - for (dirpath, dirnames, filenames) in walk("header"): + for (_, _, filenames) in walk("header"): filenames = [f for f in filenames if f.endswith( '.png') or f.endswith('.jpg')] header.extend(filenames) @@ -23,7 +23,7 @@ def headers(): def footers(): footer = [] - for (dirpath, dirnames, filenames) in walk("footer"): + for (_, _, filenames) in walk("footer"): filenames = [f for f in filenames if f.endswith( '.png') or f.endswith('.jpg')] footer.extend(filenames) @@ -31,6 +31,16 @@ def footers(): return footer +def fonts(): + fonts = [] + for (_, _, filenames) in walk("fonts"): + filenames = [f for f in filenames if f.endswith( + '.ttf')] + fonts.extend(filenames) + break + return fonts + + @app.get("/", responses={ 200: { "content": {"image/png": {}} @@ -40,15 +50,17 @@ def generate_bib( text: str, header: str, footer: str, + font: str, header_offset: Optional[int] = 60, ): - # check if header and footer are valid if header not in headers(): return {"error": "Header not found"} if footer not in footers(): return {"error": "Footer not found"} + if font not in fonts(): + return {"error": "Font not found"} image = generate_image(text, header, footer, - "agency_fb.ttf", header_offset) + font, header_offset) return Response(content=image, media_type="image/png", headers={"Content-Disposition": "filename=" + text + ".png"}) @@ -56,7 +68,10 @@ def generate_bib( def get_headers(): return headers() - @app.get("/footers") def get_footers(): return footers() + +@app.get("/fonts") +def get_fonts(): + return fonts()