This Python script automates the generation of certificates for participants based on the data provided in a CSV file. Each certificate contains the participant's name, ID, and sex, and is saved as a PNG file in the results directory.
- Python 3.x
- Required Python packages listed in
requirements.txt
- Clone or download this repository to your local machine.
- Install the required Python packages using pip:
pip install -r requirements.txt- Place your font files (
.ttfor.otf) in thefontdirectory. Make sure the font files are named correctly in the code.
- Prepare your data:
- Create a CSV file named
participants.csvin thedatadirectory. - The CSV file should contain three columns:
Name,ID, andSex. - Example:
Name,ID,Sex
John Doe,001,Male
Jane Smith,002,Female
Michael Johnson,003,Male
Emily Brown,004,Female- Run the script:
python main.py- The script will generate certificates for each participant and save them in the
resultsdirectory.
- The script uses custom fonts for the certificate generation.
- Make sure to place the font files (
.ttfor.otf) in thefontdirectory. - Update the font paths in the code if using different font files.
- The script calculates the name count (including spaces) for each participant's name and sorts the certificates based on the name count.
- If any fonts are not found, the script will print an error message and will not generate the certificates.
- The script uses the
PILlibrary to create the certificates. - Coordinates for name, ID, and sex fields (
name_x,name_y,id_x,id_y,sex_x,sex_y) can be adjusted based on the background image template structure. - If using a new background image with different dimensions, users need to adjust the alignment in the code. For adjusting alignment based on a new background image, users can refer to online tools like Image Map or other tools to determine the correct coordinates for their template structure.
The background image for the certificates should have the following specifications:
- Width: 1160 pixels
- Height: 828 pixels
- Format: PNG
- Color Mode: RGBA
Default certificate template: sample

Below is an example of a generated certificate:
This project was inspired by the need to automate certificate generation tasks, which can be time-consuming when done or design manually. The script provides an efficient solution, allowing designers, developers or users to focus on more important tasks.
