Skip to main content

Crate pix2svg

Crate pix2svg 

Source
Expand description

§pix2svg

A fast and efficient library to convert pixel art images to optimized SVG format.

§Features

  • Optimized Output: Uses greedy rectangle merging algorithm to minimize SVG file size
  • Multiple Formats: Supports PNG, JPEG, GIF, BMP, and other common image formats via the image crate
  • Transparency Support: Handles transparent pixels with configurable alpha threshold
  • Pixel Scaling: Scale up pixel art with crisp edges
  • Fast Processing: Optimized rectangle merging for efficient conversion

§Quick Start

use pix2svg::{convert_image_to_svg, ConversionOptions};
use image;

// Load an image
let img = image::open("pixel_art.png")?;

// Configure conversion options
let options = ConversionOptions {
    scale: 4,
    alpha_threshold: 1,
    ..Default::default()
};

// Convert to SVG
let svg_content = convert_image_to_svg(&img, options)?;

// Save to file
std::fs::write("output.svg", svg_content)?;

Structs§

Color
Represents a color with RGBA components
ConversionOptions
Configuration options for SVG conversion
ConversionResult
Conversion result containing SVG content and statistics
Rectangle
Represents a rectangle with position, size, and color

Functions§

convert_file_to_svg
Convert image file path to SVG format
convert_image_to_svg
Convert a dynamic image to SVG format with given options
save_svg_to_file
Save SVG content to a file
save_svg_to_file_safe
Save SVG content to a file with overwrite protection