A powerful Python tool for converting PNG images into high-quality, sharp SVG vector graphics.
- High-Quality Vectorization using potrace
- Advanced Image Preprocessing for optimal results
- 4 Quality Levels - from fast to ultra-high quality
- Batch Processing - convert entire directories
- Image Enhancement - automatic optimization for best results
- User-Friendly CLI with detailed feedback
- Cross-Platform - works on macOS, Linux, and Windows
Simplest way:
python3 png2svg.py your_image.pngThe script will automatically create your_image.svg with high quality settings.
chmod +x setup.sh
./setup.sh-
Install potrace:
# macOS brew install potrace # Ubuntu/Debian sudo apt-get install potrace # Windows # Download from: http://potrace.sourceforge.net
-
Install Python dependencies:
pip3 install -r requirements.txt
python3 png2svg.py image.png
# Creates: image.svgpython3 png2svg.py image.png -o my_logo.svgpython3 png2svg.py image.png -q ultra # Best quality
python3 png2svg.py image.png -q high # Default (recommended)
python3 png2svg.py image.png -q medium # Balanced
python3 png2svg.py image.png -q low # Fast# Convert all PNG files in a directory
python3 png2svg.py images/ --batch
# Specify output directory
python3 png2svg.py images/ --batch -o svg_output/python3 png2svg.py image.png --no-enhance| Level | Description | Best for |
|---|---|---|
ultra |
Highest quality, finest details | Logos, technical drawings |
high |
Very good quality (default) | General use |
medium |
Balanced quality vs speed | Large files, simple images |
low |
Fast conversion | Tests, previews |
- Input: PNG (including transparency)
- Output: SVG (vector format)
- Use high-contrast images - better edge detection
- Simple graphics work best - logos, icons, drawings
- Use ultra quality for detailed images
- Keep image enhancements enabled (default) for optimal results
The tool uses:
- potrace - Professional bitmap-to-vector conversion
- OpenCV - Image preprocessing and noise reduction
- Pillow - Image processing and conversion
- Click - User-friendly command line interface
Usage: png2svg.py [OPTIONS] INPUT_PATH
Options:
-o, --output TEXT Output path (file or directory)
-q, --quality [low|medium|high|ultra]
Conversion quality (default: high)
--no-enhance Disable image enhancements
--batch Batch processing for directories
--help Show this message and exit
# Convert a single PNG to SVG
python3 png2svg.py logo.png
# High quality conversion with custom name
python3 png2svg.py logo.png -q ultra -o company_logo.svg# Convert all PNGs in current directory
python3 png2svg.py . --batch
# Convert with specific quality and output directory
python3 png2svg.py images/ --batch -q high -o vectors/# Disable enhancements for pixel-perfect conversion
python3 png2svg.py pixel_art.png --no-enhance
# Ultra quality for detailed logo
python3 png2svg.py detailed_logo.png -q ultra# macOS
brew install potrace
# Ubuntu/Debian
sudo apt-get install potracepip3 install -r requirements.txt- Use
-q ultrafor highest quality - Ensure input image has good contrast
- Try upscaling the input image before conversion
- Check that input image is not corrupted
- Ensure you have write permissions in the output directory
- Try running with elevated permissions if necessary
- Low quality: ~1-2 seconds per image
- High quality: ~3-5 seconds per image
- Ultra quality: ~5-10 seconds per image
- Batch processing: Processes images sequentially
- Python 3.7+
- potrace (external binary)
- Pillow >= 10.0.0
- numpy >= 1.24.0
- opencv-python >= 4.8.0
- click >= 8.0.0
This project is open source. potrace is licensed under GNU GPL.
Contributions and bug reports are welcome! Please feel free to submit issues or pull requests.
To set up for development:
git clone <repository-url>
cd png2vec
pip3 install -r requirements.txt
./setup.shRun tests:
python3 png2svg.py test_images/ --batchDeveloped for high-quality PNG-to-SVG conversion with maximum sharpness and quality.