pix2svg
Warning: This project is mainly created by GitHub Copilot with Claude Sonnet 4. Not fully reviewd and tested yet. Use it at your own risk. PRs and issues are welcome.
A fast and efficient command-line tool to convert pixel art images to optimized SVG format with greedy rectangle merging.
Installation
From Source
The binary will be available at target/release/pix2svg.
Using Cargo
Usage
Basic Usage
# Convert image.png to image.svg
# Specify output file
# Scale pixels by 4x
# Enable verbose output
Advanced Options
# Convert with custom alpha threshold
# Scale up and specify output
Command Line Options
input: Input image file path-o, --output: Output SVG file path (default: input filename with .svg extension)-s, --scale: Pixel scale factor (1-1000, default: 1)--alpha-threshold: Minimum alpha threshold for non-transparent pixels (0-255, default: 1)--skip-transparent: Skip transparent pixels (default: true)-f, --force: Force overwrite existing output files-v, --verbose: Enable verbose output-h, --help: Show help information
Algorithm
The tool uses a greedy rectangle merging algorithm similar to the one used in Aseprite:
- Scan pixels: Process image pixel by pixel from top-left to bottom-right
- Find rectangles: For each unprocessed pixel, find the largest rectangle of the same color
- Optimize: Greedily expand rectangles horizontally and vertically
- Output: Generate SVG
<rect>elements for each rectangle
This approach significantly reduces the number of SVG elements compared to naive pixel-by-pixel conversion.
Examples
Input
Source: CC-29 Palette
464x120 = 55680 pixels

Output
4738 rectangles (8.51%)
License
This project is licensed under the MIT License - see the LICENSE file for details.