CampVerse CI
Deploy certificate generator from GitHub Actions (no binaries)
735d401
|
Raw History Blame Contribute Delete
4.32 kB
metadata
title: Certificate Generator
emoji: πŸ†
colorFrom: blue
colorTo: green
sdk: docker
sdk_version: '1.0'
app_file: api_main.py
app_port: 7860
pinned: false

Certificate Generator API

A FastAPI-based service for generating professional certificates with customizable templates, logos, signatures, and text.

Features

  • Generate certificates with custom templates
  • Support for multiple certificate types (participation/achievement)
  • Configurable logo placement and sizing
  • Digital signature support with signatory details
  • Custom font support
  • Automated text wrapping and positioning
  • PDF output format

Prerequisites

  • Python 3.8+
  • Required Python packages (see requirements.txt)
  • Storage space for templates, uploads, and generated certificates

Installation

  1. Clone the repository
  2. Install dependencies:
pip install -r requirements.txt

Directory Structure

The API automatically creates the following directory structure:

certificate_generator/
β”œβ”€β”€ uploads/           # For logos and signatures
β”œβ”€β”€ templates/         # Certificate template images
β”œβ”€β”€ fonts/            # Custom font files
└── generated_certificates/  # Output directory for PDFs

Configuration

The API uses a JSON-based configuration system with these main components:

  • Certificate type (participation/achievement)
  • Name settings (position, font, size)
  • Award text settings
  • Logo settings (left/right)
  • Signatory settings (left/right)

Default configuration is provided but can be customized via API endpoints.

API Endpoints

Information

  • GET / - API documentation and workflow
  • GET /status - Check API readiness and configuration status

Configuration

  • GET /config - Get current configuration
  • GET /config/defaults - Get default configuration
  • POST /config/certificate-type - Set certificate type
  • POST /config/name-settings - Configure name placement
  • POST /config/award-text - Configure award text
  • POST /config/logo-left - Configure left logo
  • POST /config/logo-right - Configure right logo
  • POST /config/signatory-left - Configure left signatory
  • POST /config/signatory-right - Configure right signatory
  • POST /config/reset - Reset to default configuration

File Upload

  • POST /upload-template - Upload certificate template
  • POST /upload-logo - Upload logo image
  • POST /upload-signature - Upload signature image
  • POST /upload-font - Upload custom font file

Certificate Generation

  • POST /generate - Generate certificates for list of names
  • GET /download/{filename} - Download generated certificate

Management

  • GET /files - List all uploaded and generated files
  • DELETE /clear-generated - Clear generated certificates

Usage Example

  1. Upload certificate template:
curl -X POST "http://localhost:7860/upload-template" \
  -H "accept: application/json" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@template.png" \
  -F "template_type=participation"
  1. Configure settings:
curl -X POST "http://localhost:7860/config/award-text" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "For outstanding participation in the CSI Workshop 2025",
    "position": {"x": 810, "y": 720},
    "font_size": 45,
    "max_width": 1000
  }'
  1. Generate certificates:
curl -X POST "http://localhost:7860/generate" \
  -H "accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{
    "names": ["John Doe", "Jane Smith"]
  }'

Running the API

Start the server:

python api_main.py

The API will be available at:

Error Handling

The API provides detailed error messages for:

  • Missing required files
  • Invalid file formats
  • Configuration errors
  • Generation failures

Security Considerations

  • CORS is enabled for all origins
  • File type validation for uploads
  • Size limits for uploaded files
  • Path traversal prevention

Additional Notes

  • Recommended template resolution: 2000x1500 pixels or higher
  • Supported image formats: PNG (recommended), JPEG
  • Font format: TTF only
  • Default font: DancingScript-Regular.ttf
  • Certificate output format: PDF