Skip to content

Commit

Permalink
set font
Browse files Browse the repository at this point in the history
  • Loading branch information
nimarion committed Mar 30, 2024
1 parent 498f20e commit 210d604
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Binary file added fonts/BebasNeue-Regular.ttf
Binary file not shown.
File renamed without changes.
25 changes: 20 additions & 5 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -23,14 +23,24 @@ 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)
break
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": {}}
Expand All @@ -40,23 +50,28 @@ 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"})


@app.get("/headers")
def get_headers():
return headers()


@app.get("/footers")
def get_footers():
return footers()

@app.get("/fonts")
def get_fonts():
return fonts()

0 comments on commit 210d604

Please sign in to comment.