READMEmain
We couldn't render this README. Read it on GitHub
Image Format Converter
A simple Python tool that converts images between different formats using PIL (Python Imaging Library).
Features
- Converts images to various formats supported by PIL
- Handles RGBA to RGB conversion for JPEG output (with white background)
- Saves converted images in a
converteddirectory - Supports common image formats including PNG, JPEG/JPG, BMP, GIF, and more
Installation
- Install the required dependencies:
pip install Pillow mcp
- Clone or download this repository
Usage
The tool consists of two main files:
Server (image_converter_server.py)
- Implements the image conversion logic
- Handles format validation
- Creates a
converteddirectory for output files - Manages RGBA to RGB conversion for JPEG format
- Runs as a service using FastMCP
Client (test_server.py)
- Connects to the conversion service
- Sends conversion requests
- Receives paths to converted images
Example Usage
-
First, ensure you have an image to convert (e.g.,
test.pngin the root directory) -
Run the client script:
python test_server.py
This will:
- Start the conversion server
- Convert your image (e.g.,
test.png) to JPG format - Save the result in the
converteddirectory - Print the path to the converted image
Supported Formats
The converter supports all image formats available in PIL, including:
- JPEG/JPG
- PNG
- BMP
- GIF
- And more...
Error Handling
The converter includes error handling for common issues:
- Invalid file paths
- Unsupported formats
- Missing files
- RGBA to JPEG conversion
Directory Structure
.
├── image_converter_server.py # Server implementation
├── test_server.py # Client implementation
├── converted/ # Output directory (created automatically)
└── test.png # Example input image
Notes
- All converted images are saved with unique filenames using UUID
- The converter automatically handles RGBA to RGB conversion for JPEG output
- Input paths must be relative to the root directory for security
- Output files are saved in the
converteddirectory with their new format extension