|
1 |
| -# CertificateGenerator |
| 1 | +<p align="center"> |
| 2 | + <b>Certificate Generator</b> |
| 3 | +</p> |
| 4 | +<br> |
| 5 | +<p align="center"> |
| 6 | + <img width ="70%" src="https://user-images.githubusercontent.com/61280281/134729891-673ca940-13dd-4c51-8597-ee576267d374.png"> |
| 7 | +</p> |
| 8 | +<br> |
| 9 | +<p align="center"> A simple mass certificate generator script for the community ⚡ </p> |
| 10 | + |
| 11 | +<p align="center"> |
| 12 | + <br> |
| 13 | + <a href="main.py">Source Code</a> · |
| 14 | + <a href="#docs">Docs</a> · |
| 15 | + <a href="https://raw.githubusercontent.com/tusharnankani/CertificateGenerator/main/main.py">Raw Script</a> |
| 16 | + <br> |
| 17 | +</p> |
| 18 | +<br> |
| 19 | + |
| 20 | + |
| 21 | +### Docs |
| 22 | + |
| 23 | +All you need |
| 24 | + |
| 25 | +- Certificate |
| 26 | + - Design a [simple template](template.png) on [Canva](https://www.canva.com/) |
| 27 | +- Font |
| 28 | + - A .ttf (True-Type Font) file like [this](/font), can simply be downloaded from [here](https://www.google.com/search?q=download+.ttf+fonts). |
| 29 | +- Names |
| 30 | + - Finally, a list of names in a .txt format or a .csv format. |
| 31 | + |
| 32 | +<br> |
| 33 | + |
| 34 | +### Pillow module |
| 35 | + |
| 36 | +Using the [pillow module](https://pypi.org/project/Pillow/) to make changes. |
| 37 | +<br> |
| 38 | +- Calculating and declaring default values. |
| 39 | +```python |
| 40 | +from PIL import Image, ImageFont, ImageDraw |
| 41 | + |
| 42 | +# Global Variables |
| 43 | +FONT_FILE = ImageFont.truetype(r'font/GreatVibes-Regular.ttf', 180) |
| 44 | +FONT_COLOR = "#FFFFFF" |
| 45 | + |
| 46 | +template = Image.open(r'template.png') |
| 47 | +WIDTH, HEIGHT = template.size |
| 48 | +``` |
| 49 | +<br> |
| 50 | + |
| 51 | +- Placing the name on the certificate and saving to a different directory. |
| 52 | +```python |
| 53 | +def make_certificates(name): |
| 54 | + '''Function to save certificates as a .png file''' |
| 55 | + |
| 56 | + image_source = Image.open(r'template.png') |
| 57 | + draw = ImageDraw.Draw(image_source) |
| 58 | + |
| 59 | + # Finding the width and height of the text. |
| 60 | + name_width, name_height = draw.textsize(name, font=FONT_FILE) |
| 61 | + |
| 62 | + # Placing it in the center, then making some adjustments. |
| 63 | + draw.text(((WIDTH - name_width) / 2, (HEIGHT - name_height) / 2 - 30), name, fill=FONT_COLOR, font=FONT_FILE) |
| 64 | + |
| 65 | + # Saving the certificates in a different directory. |
| 66 | + image_source.save("./out/" + name +".png") |
| 67 | + print('Saving Certificate of:', name) |
| 68 | + |
| 69 | +``` |
| 70 | +<br> |
| 71 | + |
| 72 | +### Names |
| 73 | + |
| 74 | +- Using `readlines()` method with a `.txt` format. |
| 75 | + |
| 76 | +```python |
| 77 | +names = [] |
| 78 | + |
| 79 | +with open('names.txt') as f: |
| 80 | + content = f.readlines() |
| 81 | + for item in content: |
| 82 | + names.append(item[:-1].title()) |
| 83 | +``` |
| 84 | +<br> |
| 85 | +- Using [pandas to read a `.csv` file](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html). |
| 86 | + |
| 87 | +```python |
| 88 | +import pandas |
| 89 | +names = pandas.read_csv('names.csv', sep='#') |
| 90 | +``` |
| 91 | + |
| 92 | +## Author |
| 93 | + |
| 94 | +- [Tushar Nankani](https://www.linkedin.com/in/tusharnankani/) |
2 | 95 |
|
3 |
| -A simple mass certificate generator script for the community ⚡ |
|
0 commit comments