Features: - Add ENABLE_UI and ENABLE_API environment variables for deployment flexibility - Add API URL display textbox with copy button in web interface - Create /api/calculate-auto-values endpoint to centralize sizing logic - Dimension overlay now calls API for accurate calculations instead of duplicating logic Improvements: - Enhance auto-sizing algorithm with aspect-ratio awareness - Improve padding calculation using geometric mean formula - Font detection now uses all available fonts from get_available_fonts() - API URL includes all parameters (font_path, font_size, padding, etc.) UI/UX: - Remove hidden header section and logo copy buttons - API URL textarea wraps and grows vertically to show full URL - Clean up unused code and debug console.log statements Dependencies: - Add gunicorn==21.2.0 to requirements.txt Documentation: - Document environment variables with Docker and Python examples - Add production deployment guidance - Update API documentation with font_path parameter - Add API URL feature to usage instructions Bug fixes: - Change debug=False for production - Remove unused 're' import from app.py
📺 Logo Text Adder
A Python web application for adding custom text to TV station and network logos. Upload a logo, specify your text and positioning preferences, and download the enhanced image with expanded canvas.
Features
- 🎨 Web Interface: User-friendly web UI for easy logo processing
- 🔌 REST API: Programmatic access for automation
- 📐 Flexible Positioning: Add text above, below, left, or right of logos
- 🎨 Customization: Adjust font size, text color, background color, and padding
- 📦 Multiple Formats: Supports PNG, JPG, JPEG, GIF, and WEBP
- ⚡ Instant Preview: See results immediately in the browser
Quick Start
Using Python Directly
If you prefer to run the application without Docker:
-
Clone the repository (or download the files):
git clone <repository-url> cd logo-txt -
Install Python dependencies:
pip install -r requirements.txtOr with a virtual environment (recommended):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt -
Run the application:
python app.pyFor production deployment, use Gunicorn instead:
gunicorn --bind 0.0.0.0:5001 --workers 4 app:app -
Access the application: Open your browser and navigate to
http://localhost:5001 -
Stop the application: Press
Ctrl+Cin the terminal
Using Docker Compose (Recommended)
-
Create a
docker-compose.ymlfile:services: logo-txt: image: ghcr.io/sethwv/logo-txt:latest ports: - "5001:5001" restart: unless-stopped -
Start the application:
docker compose up -d -
Access the application: Open your browser and navigate to
http://localhost:5001 -
Stop the application:
docker compose down
Using Docker Run
-
Pull and run the container:
docker run -d -p 5001:5001 --name logo-txt ghcr.io/sethwv/logo-txt:latest -
Access the application: Open your browser and navigate to
http://localhost:5001 -
Stop the container:
docker stop logo-txt docker rm logo-txt
Usage
Web Interface
- Open your browser and navigate to
http://localhost:5001 - Upload your logo image or enter an image URL
- Enter the text you want to add
- Choose the position (above, below, left, or right)
- Optionally adjust advanced settings:
- Font (default: auto - automatically detects best match)
- Font size (default: auto - scales based on image size)
- Padding (default: auto - scales based on font size)
- Text color (default: white)
- Background color (default: transparent)
- Click "Generate Logo"
- Preview and download your enhanced logo
- Copy the API URL shown below the preview to use the same settings programmatically
API Usage
The application provides a REST API endpoint for programmatic access.
Process Image from URL
GET /api/image
Process an image from a URL using query parameters. The image is returned directly.
Query Parameters
url(string, required): URL of the image to processtext(string, required): Text to add to the imageposition(string, optional): Where to place the text (above,below,left, orright) - default:belowfont_size(integer or "auto", optional): Font size in pixels, or "auto" for automatic sizing - default:autofont_path(string, optional): Path to a specific font file to use, or "auto" for automatic detection - default:autotext_color(string, optional): Text color - default:whitebg_color(string, optional): Background color or "transparent" - default:transparentpadding(integer or "auto", optional): Padding in pixels or "auto" - default:auto
Example URLs
Basic usage:
http://localhost:5001/api/image?url=https://example.com/logo.png&text=Breaking%20News
With all parameters:
http://localhost:5001/api/image?url=https://example.com/logo.png&text=Breaking%20News&position=below&font_size=auto&text_color=white&bg_color=transparent&padding=auto
Example with cURL
curl "http://localhost:5001/api/image?url=https://example.com/logo.png&text=Breaking%20News&position=below" \
--output processed_logo.png
Example with Python
import requests
url = "http://localhost:5001/api/image"
params = {
"url": "https://example.com/logo.png",
"text": "Breaking News",
"position": "below",
"font_size": "auto",
"text_color": "white",
"bg_color": "transparent"
}
response = requests.get(url, params=params)
if response.status_code == 200:
with open("processed_logo.png", "wb") as f:
f.write(response.content)
print("Image processed successfully!")
else:
print(f"Error: {response.json()}")
Example with JavaScript
const params = new URLSearchParams({
url: 'https://example.com/logo.png',
text: 'Breaking News',
position: 'below',
font_size: 'auto',
text_color: 'white',
bg_color: 'transparent'
});
const response = await fetch(`http://localhost:5001/api/image?${params}`);
if (response.ok) {
const blob = await response.blob();
const url = URL.createObjectURL(blob);
// Use the URL to display or download the image
} else {
const error = await response.json();
console.error('Error:', error);
}
Project Structure
logo-txt/
├── app.py # Flask application and image processing logic
├── templates/
│ └── index.html # Web interface
├── uploads/ # Temporary storage for uploaded images (auto-created)
├── requirements.txt # Python dependencies
├── Dockerfile # Docker image configuration
├── docker-compose.yml # Docker Compose configuration
└── README.md # This file
How It Works
- Image Upload: User uploads a logo through the web interface or API
- Canvas Expansion: The application calculates the required canvas size based on text dimensions and position
- Text Rendering: Text is rendered with the specified styling on the expanded canvas
- Image Composition: The original logo and text are composited onto the new canvas
- Output: The processed image is returned to the user for download
Configuration
Environment Variables
The application supports the following environment variables for controlling functionality:
-
ENABLE_UI(default:true)- Set to
falseto disable the web interface - Useful for API-only deployments
- Accepted values:
true,false,1,0,yes,no,on,off - Example:
ENABLE_UI=false
- Set to
-
ENABLE_API(default:true)- Set to
falseto disable all API endpoints - Useful for UI-only deployments or security requirements
- Accepted values:
true,false,1,0,yes,no,on,off - Example:
ENABLE_API=false
- Set to
Using with Docker Compose
Add environment variables to your docker-compose.yml:
services:
logo-txt:
image: ghcr.io/sethwv/logo-txt:latest
ports:
- "5001:5001"
environment:
- ENABLE_UI=true
- ENABLE_API=true
restart: unless-stopped
Using with Docker Run
Pass environment variables with the -e flag:
docker run -d -p 5001:5001 \
-e ENABLE_UI=true \
-e ENABLE_API=false \
--name logo-txt \
ghcr.io/sethwv/logo-txt:latest
Using with Python Directly
Set environment variables before running the application:
# Linux/macOS
export ENABLE_UI=true
export ENABLE_API=true
python app.py
# Windows (Command Prompt)
set ENABLE_UI=true
set ENABLE_API=true
python app.py
# Windows (PowerShell)
$env:ENABLE_UI="true"
$env:ENABLE_API="true"
python app.py
Docker Configuration
The application runs on port 5001 by default. To change the port, modify the docker-compose.yml file:
ports:
- "8080:5001" # Maps host port 8080 to container port 5001
Application Settings
You can modify these settings in app.py:
MAX_CONTENT_LENGTH: Maximum upload file size (default: 16MB)UPLOAD_FOLDER: Temporary folder for uploads (default: 'uploads')- Server host and port in the
if __name__ == '__main__'block
Note: The built-in Flask development server (python app.py) is not suitable for production. For production deployments:
- Docker (recommended): Uses Gunicorn automatically with 4 workers
- Manual deployment: Use
gunicorn --bind 0.0.0.0:5001 --workers 4 app:app - Adjust
--workersbased on available CPU cores (recommended: 2-4 × CPU cores) - Increase
--timeoutfor processing large images (default in Docker: 120 seconds)
Troubleshooting
Port Already in Use
If port 5001 is already in use, change the port mapping in docker-compose.yml:
ports:
- "8080:5001" # Use port 8080 instead
Then access the application at http://localhost:8080
Font Issues
The Docker image includes DejaVu and Liberation fonts by default. If you need additional fonts, you can:
- Modify the Dockerfile to install additional font packages
- Mount a font directory as a volume in
docker-compose.yml
View Container Logs
docker compose logs -f
License
This project is provided as-is for personal and commercial use.
Contributing
Feel free to submit issues, fork the repository, and create pull requests for any improvements.