A small Rust tool and library that converts raster images (PNG, JPG, BMP) to SVG vector graphics using the vtracer crate for high-quality tracing.
For a short project overview see PROJECT_SUMMARY.md. For full usage details and examples see docs/USAGE.md.
- Multi-format support: PNG, JPG, BMP and other common formats
- Multiple color modes: full color, binary (black/white), posterized
- Preprocessing filters: gaussian and median filters
- Preprocessing filters: gaussian (lightweight blur preprocessing)
- Tunable parameters: smoothness, pixel size, number of colors
- Advanced curve tracing: splines and corner-cut support
- Detailed logging and multiple verbosity levels
- CLI with convenient options and built-in presets
Requirements:
- Rust (1.70+)
- Cargo
Build:
git clone <repo>
cd rsvg
cargo build --releaseThe compiled executable will be at target/release/pic2svg.
Basic syntax:
pic2svg -i <input_image> [-o <output_svg>]Examples:
pic2svg -i photo.png -o photo.svg
pic2svg -i logo.png # produces logo.svg
pic2svg -i signature.png -o sig.svg --color-mode binary -t 180For more examples and advanced options see docs/USAGE.md.
Add the crate to your Cargo.toml:
[dependencies]
rsvg = "0.1.0"Example:
use rsvg::{convert_file_to_svg, ConversionConfig};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ConversionConfig::default();
convert_file_to_svg(
Path::new("input.png"),
Path::new("output.svg"),
&config,
)?;
Ok(())
}Built-in presets include presets::logo(), presets::photo(), presets::sketch(), presets::illustration(), presets::high_quality() and presets::fast().
Common issues and quick fixes:
| Problem | Quick Fix |
|---|---|
| Output looks pixelated | Increase --smoothness and/or decrease --pixel-size |
| Colors look off | Adjust --colors or use --color-mode color |
| Conversion too slow | Reduce input resolution or increase --pixel-size |
| Jagged edges | Apply --filter gaussian |
| Unwanted background | Try binary mode and tune --threshold |
vtracer— vector tracing engineimage— image decoding and basic processingclap— CLI argument parsinganyhow— error handlinglog/env_logger— logging
Contributions welcome: open an issue or submit a pull request with improvements, tests or documentation.
This project is licensed under the MIT License (see LICENSE).
Enjoy converting your images to SVG! 🎨