A high-performance image generation service that creates images with text overlays using custom fonts.
- Purpose
- Features
- Usage
- Prerequisites
- Installation
- Configuration
- Development
- Docker Support
- Logging
- Contributing
- Acknowledgments
- License
This project provides a RESTful API for generating images dynamically based on various parameters. The API allows users to specify the image dimensions, background color, text content, text color, and font size to create customized images.
- Dynamic image generation: Creates images on-the-fly based on user-provided parameters
- Customizable parameters: Allows users to specify dimensions, colors, text, and font size
- Flexible API endpoints: Offers multiple endpoints for different image sizes and parameters
- Performance optimization: Leverages efficient image generation techniques for optimal performance
- Font management system with support for TTF, OTF, WOFF, and WOFF2 fonts
- RESTful API endpoints with health checks
- Graceful shutdown handling
- Structured JSON logging
- Docker support
- Configurable via environment variables
GET /health
- Health check endpointGET /img/{width}/{height}[/{bgColor}/{text}/{textColor}/{fontSize}]
- Generate image with text- Parameters:
width
: Image width in pixelsheight
: Image height in pixelsbgColor
: Background color in hex format (optional)text
: Text content to display (optional)textColor
: Text color in hex format (optional)fontSize
: Font size in pixels (optional)
- Parameters:
Generate a simple image:
http://localhost:8080/img/500/450
Generate an image with text:
http://localhost:8080/img/800/250/1D7373/Hello%20World/FFFFFF/100
This will create an image with:
- Width: 800 pixels
- Height: 250 pixels
- Background color: #1D7373
- Text: "Hello World"
- Text color: #FFFFFF
- Font size: 100
The API has been designed with performance in mind. Benchmark tests using wrk have demonstrated high request rates and low latency:
# Small image (100x100)
Requests/sec: 450.64
Transfer/sec: 473.53KB
# Minimal image (1x1)
Requests/sec: 524.48
Transfer/sec: 358.53KB
# Health check endpoint
Requests/sec: 61235.01
Transfer/sec: 7.01MB
- Go 1.24 or higher
- Docker (optional, for containerized deployment)
- Make (for using Makefile commands)
- Clone the repository:
git clone https://github.com/romanitalian/img-generate.git
cd img-generate
- Install dependencies:
go mod download
- Build the application:
make build
Build and run using Docker:
make docker-build
make docker-run
The service can be configured using environment variables:
Variable | Description | Default |
---|---|---|
PORT |
Server port | 8080 |
FONT_DIR |
Directory for font files | ./fonts |
LOG_LEVEL |
Logging level (debug, info, warn, error) | info |
make help
- Show available commandsmake deps
- Download dependenciesmake build
- Build the application (development)make build-prod
- Build the application (production)make run
- Run the applicationmake test
- Run testsmake clean
- Clean build artifactsmake lint-install
- Install golangci-lintmake lint
- Run linter with full outputmake fmt
- Format codemake docker-build
- Build Docker imagemake docker-run
- Run Docker containermake docker-clean
- Clean Docker resources
make build
The binary will be created in the bin
directory.
make docker-build
make docker-run
make docker-clean
The service uses structured JSON logging with the following levels:
- DEBUG: Detailed debugging information
- INFO: General operational information
- WARN: Warning messages
- ERROR: Error messages
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.