Skip to content

Commit

Permalink
remove hardcoded folders
Browse files Browse the repository at this point in the history
  • Loading branch information
nimarion committed Apr 1, 2024
1 parent 210d604 commit b613ae1
Show file tree
Hide file tree
Showing 27 changed files with 27 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,4 @@ pyrightconfig.json
.history
.ionide

output

# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# bib-generator

Automatically generate DIN A5 (148 x 210) bibs for sports events. Text size is automatically adjusted to fit the bib. Supports custom fonts, headers and footers.

## Using csv file

- [Example file](data.dsv)



```bash
python3 .\main.py --excel .\data.xlsx --output .\output\ --font .\agency_fb.ttf --header-offset 60
python3 .\main.py --data .\example\data.csv --footer .\example\footer.png --output .\example\output\ --font .\example\agency_fb.ttf --header-offset 60 --seperator ';'
```

## Manual input

```bash
python3 .\bib.py --text MARION --output NiklasMarion.png --header .\header\lotto.png --footer .\footer\rehlingen.png --font .\agency_fb.ttf --header-offset 60
python3 .\bib.py --text LYLES --output .\example\output\Lyles.png --header .\example\globus.png --font .\example\agency_fb.ttf --footer .\example\footer.png --header-offset 60--footer .\example\footer.png --header-offset 60
```

![image](https://github.com/nimarion/bib-generator/assets/23435250/5a7272fb-e5bb-4117-b3e0-b769daf06912)
Expand Down
4 changes: 2 additions & 2 deletions bib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
def generate_image(txt, header_file, footer_file, font_file, header_offset = 0):
# A5 size
image = Image.new("RGB", (3508, 2480), "white")
header = Image.open("header/" + header_file)
footer = Image.open("footer/" + footer_file)
header = Image.open(header_file)
footer = Image.open(footer_file)
draw = ImageDraw.Draw(image)
fontsize = 1 # starting font size

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
5 changes: 5 additions & 0 deletions example/data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
firstname;lastname;header
Imke;Onnen;example/globus.png
Luna;Thiel;example/bitburger.png
Joshua;Abuaku;example/bitburger.png
Alexandra;Bell;example/globus.png
File renamed without changes
File renamed without changes
File renamed without changes.
Binary file added example/output/Abuaku_Joshua.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/output/Bell_Alexandra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/output/Lyles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/output/Onnen_Imke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/output/Thiel_Luna.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file removed header/.gitkeep
Empty file.
Binary file removed header/edeka.png
Binary file not shown.
Binary file removed header/ford.png
Binary file not shown.
Binary file removed header/heitz.png
Binary file not shown.
Binary file removed header/ikk.png
Binary file not shown.
Binary file removed header/innenministerium.png
Binary file not shown.
Binary file removed header/ksk.png
Binary file not shown.
Binary file removed header/lotto.png
Binary file not shown.
Binary file removed header/shs.png
Binary file not shown.
Binary file removed header/vse.png
Binary file not shown.
Binary file removed header/vvb.png
Binary file not shown.
16 changes: 8 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
argparse = argparse.ArgumentParser(
prog='Bib Generator')
argparse.add_argument(
'--excel', '-e', help='Excel file name', required=True)
'--data', '-d', help='CSV file name', required=True)
argparse.add_argument('--seperator', '-s', help='CSV seperator', default=',', required=False)
argparse.add_argument(
'--output', '-o', help='Output folder', required=True)
argparse.add_argument('--font', '-F', help='Font file name', required=True)
Expand All @@ -17,20 +18,19 @@

args = argparse.parse_args()

excel_file = args.excel
data_file = args.data
output_folder = args.output
font_file = args.font
footer_file = args.footer
header_offset = args.header_offset

df = pd.read_excel(excel_file)
df = pd.read_csv(data_file, sep=args.seperator)

for index, row in df.iterrows():
firstname = row['Vorname']
lastname = row['Nachname']
firstname = row['firstname']
lastname = row['lastname']
text = lastname.upper()
sponsor = row['Sponsor']
header_file = sponsor + ".png"
header_file = row['header']
output_file = output_folder + "/" + lastname + "_" + firstname + ".png"
print("Generating bib for", firstname, lastname, "with sponsor", sponsor)
print("Generating bib for", firstname, lastname, "with header", header_file)
bib_generator(text, output_file, header_file, footer_file, font_file, header_offset)

0 comments on commit b613ae1

Please sign in to comment.