Skip to content

visualy-at/png2svg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PNG2SVG - High-Quality Vectorization

A powerful Python tool for converting PNG images into high-quality, sharp SVG vector graphics.

Features

  • 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

Quick Start

Simplest way:

python3 png2svg.py your_image.png

The script will automatically create your_image.svg with high quality settings.

Installation

Automatic Installation (Recommended)

chmod +x setup.sh
./setup.sh

Manual Installation

  1. Install potrace:

    # macOS
    brew install potrace
    
    # Ubuntu/Debian
    sudo apt-get install potrace
    
    # Windows
    # Download from: http://potrace.sourceforge.net
  2. Install Python dependencies:

    pip3 install -r requirements.txt

Usage

Single File Conversion

python3 png2svg.py image.png
# Creates: image.svg

Custom Output Name

python3 png2svg.py image.png -o my_logo.svg

Quality Levels

python3 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

Batch Processing

# Convert all PNG files in a directory
python3 png2svg.py images/ --batch

# Specify output directory
python3 png2svg.py images/ --batch -o svg_output/

Disable Image Enhancements

python3 png2svg.py image.png --no-enhance

Quality Levels

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

Supported Formats

  • Input: PNG (including transparency)
  • Output: SVG (vector format)

Tips for Best Results

  1. Use high-contrast images - better edge detection
  2. Simple graphics work best - logos, icons, drawings
  3. Use ultra quality for detailed images
  4. Keep image enhancements enabled (default) for optimal results

Technical Details

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

Command Line Options

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

Examples

Basic Usage

# 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

Batch Processing

# 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/

Advanced Usage

# 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

Troubleshooting

"potrace not found"

# macOS
brew install potrace

# Ubuntu/Debian
sudo apt-get install potrace

"Module not found"

pip3 install -r requirements.txt

Poor Quality Results

  • Use -q ultra for highest quality
  • Ensure input image has good contrast
  • Try upscaling the input image before conversion
  • Check that input image is not corrupted

Permission Errors

  • Ensure you have write permissions in the output directory
  • Try running with elevated permissions if necessary

Performance

  • 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

Dependencies

  • Python 3.7+
  • potrace (external binary)
  • Pillow >= 10.0.0
  • numpy >= 1.24.0
  • opencv-python >= 4.8.0
  • click >= 8.0.0

License

This project is open source. potrace is licensed under GNU GPL.

Contributing

Contributions and bug reports are welcome! Please feel free to submit issues or pull requests.

Development

To set up for development:

git clone <repository-url>
cd png2vec
pip3 install -r requirements.txt
./setup.sh

Run tests:

python3 png2svg.py test_images/ --batch

Developed for high-quality PNG-to-SVG conversion with maximum sharpness and quality.

About

convert your png logos into svg

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published