π Revolutionary PNG/JPG to SVG converter with THREE advanced algorithms - pixel rectangles, contour paths, and smart polygon simplification using Douglas-Peucker algorithm.
- π― Three Conversion Methods: Choose the best algorithm for your needs
- π₯ Smart Polygons: Douglas-Peucker algorithm for optimal shape simplification
- π Pixel-Perfect Accuracy: Every black pixel preserved as SVG rectangles
- π¨ Smooth Contours: Vector paths following original image shapes
- β‘ High Performance: Optimized algorithms with progress bars
- ποΈ Flexible Options: Resolution scaling, negative inversion, custom thresholds
- π» Cross-Platform: Windows EXE and Python script versions
# Download png2svg.exe from releases
png2svg.exe image.png --smart # Smart polygons (recommended)
png2svg.exe image.png --contours # Smooth contours
png2svg.exe image.png # Pixel rectangles (default)git clone https://github.com/ussdeveloper/png2svg.git
cd png2svg
pip install -r requirements.txt
python png2svg.py image.png --smartBest for: Logos, graphics, geometric shapes
png2svg.exe image.png output.svg --smart --resolution 300- Algorithm: Douglas-Peucker polygon simplification
- Process: Find contours β Simplify vertices β Merge close points β Smooth curves
- Result: Minimal SVG elements with maximum quality
- Example: 2000+ rectangles β 4 smart polygons (99.8% reduction!)
Best for: Organic shapes, illustrations
png2svg.exe image.png output.svg --contours --resolution 300- Algorithm: OpenCV contour detection
- Process: Edge detection β Path tracing β SVG conversion
- Result: Vector paths following image boundaries
- Example: Complex shape β 5-15 smooth SVG paths
Best for: Pixel art, absolute precision needed
png2svg.exe image.png output.svg --resolution 400- Algorithm: Pixel grouping and rectangle optimization
- Process: Scan pixels β Group adjacent β Create rectangles β Optimize
- Result: 100% accurate pixel reproduction
- Example: Every black pixel becomes SVG rectangle
| Method | Elements | File Size | Quality | Speed | Best For |
|---|---|---|---|---|---|
| Smart Polygons | 4-10 | Smallest | Excellent | Fastest | Logos, Graphics |
| Contour Paths | 5-50 | Small | Very Good | Fast | Illustrations |
| Pixel Rectangles | 100-5000+ | Large | Perfect | Slower | Pixel Art |
png2svg.exe input.png [output.svg] [options]
Positional Arguments:
input Input PNG/JPG file
output Output SVG file (optional)
Conversion Methods:
--smart Smart polygons (Douglas-Peucker + smoothing)
--contours Contour paths (original shapes)
(default) Pixel rectangles (absolute precision)
Quality Options:
--resolution [100-1000] SVG resolution % (default: 100%)
--scale [1-10] Image scale factor (default: 5)
--threshold [1-255] Binarization threshold (default: 128)
Image Processing:
--no-negative Disable negative inversion (enabled by default)# Smart polygons (recommended for most cases)
png2svg.exe logo.png logo.svg --smart
# High resolution with smart polygons
png2svg.exe image.png output.svg --smart --resolution 500
# Contour paths for illustrations
png2svg.exe drawing.png vector.svg --contours --resolution 300
# Pixel-perfect conversion
png2svg.exe pixelart.png precise.svg --resolution 200# Disable negative inversion (for black backgrounds)
png2svg.exe image.png --smart --no-negative
# Custom threshold for fine-tuning
png2svg.exe image.png --contours --threshold 100 --resolution 400
# Maximum quality with smart polygons
png2svg.exe logo.png --smart --resolution 1000 --scale 8The smart polygon method implements the Douglas-Peucker line simplification algorithm:
- Contour Detection: Find shape boundaries using OpenCV
- Polygon Simplification: Reduce vertices while preserving shape accuracy
- Point Merging: Combine nearby vertices for cleaner output
- Smooth Path Generation: Create optimized SVG paths with curves
Benefits:
- 95-99% reduction in SVG elements
- Maintains visual fidelity
- Creates scalable vector graphics
- Optimized for geometric shapes
Advanced rectangle packing algorithm:
- Horizontal Scanning: Find maximum width rectangles
- Vertical Extension: Extend rectangles downward when possible
- Optimization: Minimize total rectangle count
- Pixel Accuracy: Every source pixel represented
OpenCV-based vector tracing:
- Edge Detection: Identify shape boundaries
- Hierarchy Processing: Handle nested shapes correctly
- Path Conversion: Transform contours to SVG paths
- Hole Support: Proper handling of complex shapes with holes
- Python 3.8+ (for script version)
- Windows 10+ (for EXE version)
pip install opencv-python numpy svgwritegit clone https://github.com/ussdeveloper/png2svg.git
cd png2svg
pip install -r requirements.txt
# Run directly
python png2svg.py image.png output.svg --smart
# Build EXE (Windows)
./build.bat
# Build on Linux/macOS
./build.shbuild.bat # Automatic build with dependency checkchmod +x build.sh
./build.sh # Cross-platform build scriptBuild Features:
- β Automatic dependency installation
- β Clean build process (removes old artifacts)
- β Executable testing and validation
- β PyInstaller optimization for smaller file size
Input: company_logo.png (complex logo)
Method: --smart --resolution 300
Result: 6 SVG polygons instead of 3,247 rectangles
Size: 89% smaller file, vector scalable
Input: drawing.png (hand-drawn illustration)
Method: --contours --resolution 200
Result: 23 smooth SVG paths
Size: Vector-perfect curves, artistic quality preserved
Input: sprite.png (16x16 pixel character)
Method: default --resolution 800
Result: 94 optimized rectangles
Size: 100% pixel accuracy, 8x scale factor
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Make changes and test thoroughly
- Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
git clone https://github.com/ussdeveloper/png2svg.git
cd png2svg
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python png2svg.py --helpMIT License - see LICENSE file for details.
- Repository: https://github.com/ussdeveloper/png2svg
- Issues: https://github.com/ussdeveloper/png2svg/issues
- Releases: https://github.com/ussdeveloper/png2svg/releases
| Feature | Smart Polygons | Contour Paths | Pixel Rectangles |
|---|---|---|---|
| Element Count | βββββ (Minimal) | ββββ (Low) | ββ (High) |
| File Size | βββββ (Smallest) | ββββ (Small) | ββ (Large) |
| Accuracy | ββββ (Excellent) | ββββ (Very Good) | βββββ (Perfect) |
| Speed | βββββ (Fastest) | ββββ (Fast) | βββ (Moderate) |
| Scalability | βββββ (Infinite) | βββββ (Infinite) | βββββ (Infinite) |
π Transform your images into perfect vectors with PNG2SVG!