Skip to content

Pablushka/rsvg

Repository files navigation

pic2svg — Image to SVG Converter

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.

Features

  • 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

Installation

Requirements:

  • Rust (1.70+)
  • Cargo

Build:

git clone <repo>
cd rsvg
cargo build --release

The compiled executable will be at target/release/pic2svg.

Quick Start (CLI)

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 180

For more examples and advanced options see docs/USAGE.md.

Library Usage

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().

Troubleshooting

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

Dependencies

  • vtracer — vector tracing engine
  • image — image decoding and basic processing
  • clap — CLI argument parsing
  • anyhow — error handling
  • log / env_logger — logging

Contributing

Contributions welcome: open an issue or submit a pull request with improvements, tests or documentation.

License

This project is licensed under the MIT License (see LICENSE).

Enjoy converting your images to SVG! 🎨

About

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.

Resources

License

Stars

Watchers

Forks

Contributors