### VTracer: Installation and Setup Instructions Source: https://context7.com/visioncortex/vtracer/llms.txt Provides instructions for installing the VTracer library using various package managers and build systems. This includes Rust's Cargo, Python's pip, building from source, and preparing the WebAssembly version. ```bash # Rust installation from crates.io cargo install vtracer # Python installation from PyPI pip install vtracer # Add as Rust dependency in Cargo.toml cargo add vtracer # Or manually edit Cargo.toml # [dependencies] # vtracer = "0.6" # visioncortex = "0.8" # Build from source git clone https://github.com/visioncortex/vtracer.git cd vtracer cargo build --release # Install Python package from source cd cmdapp pip install . # Run tests cargo test # Build WebAssembly version cd webapp wasm-pack build --target web ``` -------------------------------- ### Initialize Microsoft Clarity Analytics Source: https://github.com/visioncortex/vtracer/blob/master/docs/index.html This JavaScript snippet initializes the Microsoft Clarity analytics tool. It should be included in the head of your HTML document to start tracking user interactions on your website. It requires no external dependencies other than the browser's global `window` and `document` objects. ```javascript VTracer (function(c,l,a,r,i,t,y){ c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)}; t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i; y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y); })(window, document, "clarity", "script", "403biw7tra"); ``` -------------------------------- ### Install VTracer Python Package Source: https://github.com/visioncortex/vtracer/blob/master/cmdapp/vtracer/README.md This command installs the VTracer Python package using pip. Ensure you have Python and pip installed on your system. This is the first step to use VTracer's Python functionalities. ```shell pip install vtracer ``` -------------------------------- ### Convert Image to SVG (Python) Source: https://github.com/visioncortex/vtracer/blob/master/cmdapp/vtracer/README.md Demonstrates basic image to SVG conversion using VTracer's Python library. It shows examples for default multicolor conversion and a faster single-color (binary) mode, suitable for line art. Input and output file paths are specified. ```python import vtracer input_path = "/path/to/some_file.jpg" output_path = "/path/to/some_file.vtracer.jpg" # Minimal example: use all default values, generate a multicolor SVG vtracer.convert_image_to_svg_py(inp, out) # Single-color example. Good for line art, and much faster than full color: vtracer.convert_image_to_svg_py(inp, out, colormode='binary') ``` -------------------------------- ### Advanced VTracer Conversion Options (Python) Source: https://github.com/visioncortex/vtracer/blob/master/cmdapp/vtracer/README.md This Python example showcases the extensive configuration options available for VTracer's image to SVG conversion. It demonstrates how to fine-tune parameters such as color mode, hierarchy, shape mode, filtering, precision, and thresholds to achieve specific vectorization results. These options are applicable to `convert_image_to_svg_py`, `convert_raw_image_to_svg`, and `convert_pixels_to_svg`. ```python import vtracer inp = "/path/to/input.jpg" out = "/path/to/output.svg" # All the bells & whistles, also applicable to convert_raw_image_to_svg and convert_pixels_to_svg. vtracer.convert_image_to_svg_py(inp, out, colormode = 'color', # ["color"] or "binary" hierarchical = 'stacked', # ["stacked"] or "cutout" mode = 'spline', # ["spline"] "polygon", or "none" filter_speckle = 4, # default: 4 color_precision = 6, # default: 6 layer_difference = 16, # default: 16 corner_threshold = 60, # default: 60 length_threshold = 4.0, # in [3.5, 10] default: 4.0 max_iterations = 10, # default: 10 splice_threshold = 45, # default: 45 path_precision = 3 # default: 8 ) ``` -------------------------------- ### Rust: Config Presets for Image to SVG Conversion Source: https://context7.com/visioncortex/vtracer/llms.txt Demonstrates using predefined configuration presets (Bw, Poster, Photo) for image to SVG conversion in Rust. It also shows how to customize a preset by modifying its fields. This allows for quick optimization based on image type. ```rust use vtracer::{Config, Preset, convert_image_to_svg}; use std::path::Path; fn main() -> Result<(), String> { // Black and white preset - fast processing for line art let bw_config = Config::from_preset(Preset::Bw); convert_image_to_svg( Path::new("lineart.png"), Path::new("lineart.svg"), bw_config )?; // Poster preset - balanced quality for illustrations let poster_config = Config::from_preset(Preset::Poster); convert_image_to_svg( Path::new("poster.jpg"), Path::new("poster.svg"), poster_config )?; // Photo preset - high quality for photographs let photo_config = Config::from_preset(Preset::Photo); convert_image_to_svg( Path::new("photo.jpg"), Path::new("photo.svg"), photo_config )?; // Customize a preset let mut custom_config = Config::from_preset(Preset::Poster); custom_config.filter_speckle = 8; // Increase noise filtering custom_config.path_precision = Some(3); // More precision in paths convert_image_to_svg( Path::new("custom.png"), Path::new("custom.svg"), custom_config )?; Ok(()) } ``` -------------------------------- ### Rust: In-Memory Image to SVG Conversion Source: https://context7.com/visioncortex/vtracer/llms.txt Demonstrates loading an image into memory, converting it to an SVG using VTracer's `convert` function with default and custom configurations, and saving the output to a file. This process involves using the `image` crate for loading and the `vtracer` crate for conversion. ```rust use vtracer::{convert, Config, ColorImage}; use image::io::Reader as ImageReader; use std::fs::File; use std::io::Write; fn main() -> Result<(), String> { // Load image into memory let img = ImageReader::open("input.png") .map_err(|e| e.to_string())? .decode() .map_err(|e| e.to_string())? .to_rgba8(); let (width, height) = (img.width() as usize, img.height() as usize); let color_image = ColorImage { pixels: img.as_raw().to_vec(), width, height, }; // Convert to SVG in memory let config = Config::default(); let svg_file = convert(color_image, config)?; // Write SVG to file let mut file = File::create("output.svg") .map_err(|e| e.to_string())?; write!(&mut file, "{}", svg_file) .map_err(|e| e.to_string())?; // Process with custom config let config = Config { color_mode: vtracer::ColorMode::Binary, filter_speckle: 10, ..Config::default() }; let img2 = ImageReader::open("drawing.png") .map_err(|e| e.to_string())? .decode() .map_err(|e| e.to_string())? .to_rgba8(); let color_image2 = ColorImage { pixels: img2.as_raw().to_vec(), width: img2.width() as usize, height: img2.height() as usize, }; let svg_file2 = convert(color_image2, config)?; let svg_string = format!("{}", svg_file2); println!("Generated SVG: {} bytes", svg_string.len()); Ok(()) } ``` -------------------------------- ### VTracer Page Styling (CSS) Source: https://github.com/visioncortex/vtracer/blob/master/webapp/app/index.html Defines the basic styles for the VTracer web page, including full viewport dimensions for html and body, button styling, and specific styles for the file drop area, canvas container, and SVG elements. It also includes hover effects for SVG paths and styling for the options panel. ```css html, body { width: 100%; height: 100%; margin: 0; } .button { cursor: pointer; font-family: sans-serif; border-radius: 2px; border: 1px solid #aaa; padding: 4px 8px; } #droptext { border: 2px dashed #000; } #droptext.hovering { border: 2px dashed #fff; } #canvas-container { position: absolute; left: 2.5%; top: 5%; width: 95%; height: 90%; } #svg, #frame { position: absolute; width: 100%; margin-bottom: 50px; } #svg > path:hover { stroke: #ff0; } #droptext { height: 100%; text-align: center; } #options { position: absolute; left: 2.5%; top: 5%; padding: 50px; background: rgba(255,255,255,0.5); } ``` -------------------------------- ### Set Light/Dark Theme Based on System Preference Source: https://github.com/visioncortex/vtracer/blob/master/docs/index.html This JavaScript code checks the user's system color scheme preference and applies the appropriate theme (light or dark) to the VTracer application. It dynamically adds or removes CSS classes from the document body to control the visual appearance. This ensures the application respects user preferences for dark mode. ```javascript if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { document.body.classList.remove('uk-dark'); document.body.classList.add('uk-light'); } ``` -------------------------------- ### VTracer CSS Styling Source: https://github.com/visioncortex/vtracer/blob/master/docs/index.html This CSS code defines the visual styling for the VTracer project. It includes rules for general page layout, dark mode themes, specific UI elements like buttons and input sliders, and styles for image galleries and drag-and-drop areas. These styles ensure a consistent and responsive user interface across different devices and color schemes. ```css html, body { width: 100%; height: 100%; } .uk-dark body, .uk-dark .container { background: #fff; } .uk-dark #vc-logo-light { display: none; } .uk-light #vc-logo { display: none; } .uk-light body, .uk-light .container, .uk-light .uk-modal-dialog { background: #2e2e2e; } @media screen and (prefers-color-scheme: dark) { html { background: #2e2e2e; } } #droptext { background: #00275D; border: 2px dashed #CC972E; } #droptext.hovering { border: 2px dashed #fff; } .uk-navbar-right.uk-padding-small { padding-top: 0; padding-bottom: 0; } #export, .uk-button-group .uk-button.selected { color: #fff; background: #00275D; border-color: #CC972E; } .uk-dark #export, .uk-dark .uk-button-group .uk-button.selected { border-width: 2px; } .uk-dark #droptext { border-width: 4px; } .uk-button-group > button { padding-left: 10px; padding-right: 10px; } @media only screen and (min-width: 1280px) { .uk-button-group > button { padding-left: 25px; padding-right: 25px; } } #canvas-container { position: relative; height: max-content; } #svg, #frame { position: absolute; width: 100%; margin-bottom: 50px; } #svg > path:hover { stroke: #ff0; } #droptext { height: 480px; color: #CC972E; } input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; background: #00275D; border-color: #CC972E; } input[type=range]::-moz-range-thumb { background: #00275D; border-color: #CC972E; } input[type=range]::-ms-thumb { background: #00275D; border-color: #CC972E; } #drop, #gallery, #options { border-top: 1px solid #686868; } #gallery { padding-bottom: 0; } .galleryitem { cursor: pointer; padding: 2px; margin: 1px; } .galleryitem:hover { padding: 0px; margin: 0px; border: 2px solid #CC972E; } .galleryitem img { max-height: 120px; } .uk-text-meta { font-size: 12px; } ``` -------------------------------- ### Rust: Convert Image File to SVG with Config Source: https://context7.com/visioncortex/vtracer/llms.txt Converts an image file to an SVG file using Rust. It utilizes a `Config` struct for detailed control over vectorization parameters. The function takes input and output paths along with the configuration. ```rust use vtracer::{convert_image_to_svg, Config}; use std::path::Path; fn main() -> Result<(), String> { // Basic conversion with default config let input_path = Path::new("input.jpg"); let output_path = Path::new("output.svg"); let config = Config::default(); convert_image_to_svg(&input_path, &output_path, config)?; // Custom configuration let config = Config { color_mode: vtracer::ColorMode::Color, hierarchical: vtracer::Hierarchical::Stacked, filter_speckle: 4, color_precision: 6, layer_difference: 16, mode: visioncortex::PathSimplifyMode::Spline, corner_threshold: 60, length_threshold: 4.0, max_iterations: 10, splice_threshold: 45, path_precision: Some(2), }; convert_image_to_svg( Path::new("artwork.png"), Path::new("artwork.svg"), config )?; Ok(()) } ``` -------------------------------- ### CLI: Convert Raster to SVG with VTracer Source: https://context7.com/visioncortex/vtracer/llms.txt Use the VTracer command-line tool to convert raster images to SVG. It supports basic conversion, presets like 'bw', 'poster', and 'photo', and advanced color conversion with numerous configurable parameters for precision and quality control. ```bash # Basic conversion with default settings vtracer --input photo.jpg --output photo.svg # Black and white conversion with preset vtracer --input drawing.png --output drawing.svg --preset bw # Advanced color conversion with custom parameters vtracer \ --input artwork.png \ --output artwork.svg \ --colormode color \ --hierarchical stacked \ --mode spline \ --filter_speckle 4 \ --color_precision 6 \ --corner_threshold 60 \ --segment_length 4.0 \ --splice_threshold 45 \ --path_precision 2 # Poster optimization preset (good for illustrations) vtracer --input poster.jpg --output poster.svg --preset poster # Photo preset (high quality for photographs) vtracer --input photo.jpg --output photo.svg --preset photo ``` -------------------------------- ### Convert RGBA Pixels to SVG (Python) Source: https://github.com/visioncortex/vtracer/blob/master/cmdapp/vtracer/README.md This Python code demonstrates converting RGBA image pixel data into an SVG string using VTracer. It utilizes the Pillow (PIL) library to load an image, extract its pixel data and size, and then passes this information to VTracer. This method is useful for in-memory image manipulation. ```python from PIL import Image import vtracer input_path = "/path/to/some_file.jpg" # Convert from RGBA image pixels img = Image.open(input_path).convert('RGBA') pixels: list[tuple[int, int, int, int]] = list(img.getdata()) svg_str: str = vtracer.convert_pixels_to_svg(pixels, img.size) ``` -------------------------------- ### Python: convert_image_to_svg_py Source: https://context7.com/visioncortex/vtracer/llms.txt Converts an image file to an SVG vector graphic using VTracer's Python bindings. Allows full control over color mode, hierarchical clustering, output mode, and various filtering and simplification parameters. Returns the path to the generated SVG file. ```APIDOC ## POST /convert_image_to_svg_py ### Description Converts an image file to an SVG vector graphic using VTracer's Python bindings. ### Method POST ### Endpoint convert_image_to_svg_py ### Parameters #### Request Body - **image_path** (string) - Required - Path to the input raster image. - **out_path** (string) - Required - Destination path for the generated SVG file. - **colormode** (string) - Optional - Color mode, either 'color' or 'binary'. - **hierarchical** (string) - Optional - Hierarchical clustering strategy, 'stacked' or 'cutout'. - **mode** (string) - Optional - Output mode, 'spline', 'polygon', or 'none'. - **filter_speckle** (integer) - Optional - Remove noise patches smaller than N×N pixels. - **color_precision** (integer) - Optional - Number of significant bits per RGB channel. - **layer_difference** (integer) - Optional - Color difference between gradient layers. - **corner_threshold** (integer) - Optional - Minimum angle in degrees to detect corners. - **length_threshold** (number) - Optional - Segment subdivision length threshold. - **max_iterations** (integer) - Optional - Maximum smoothing iterations. - **splice_threshold** (integer) - Optional - Minimum angle for spline splicing. - **path_precision** (integer) - Optional - Decimal places in SVG path strings. ### Request Example { "image_path": "artwork.png", "out_path": "artwork.svg", "colormode": "color", "hierarchical": "stacked", "mode": "spline", "filter_speckle": 4, "color_precision": 6, "corner_threshold": 60, "length_threshold": 4.0, "path_precision": 3 } ### Response #### Success Response (200) - **svg_path** (string) - Path to the generated SVG file. ### Response Example { "svg_path": "artwork.svg" } ``` -------------------------------- ### Python: Convert Image Files to SVG with vtracer Source: https://context7.com/visioncortex/vtracer/llms.txt Convert image files to SVG directly from Python using the `vtracer.convert_image_to_svg_py` function. This function allows full control over conversion parameters, including color mode, hierarchical strategies, output modes, and various filtering and precision settings. It also includes basic error handling. ```python import vtracer # Basic usage - convert with all defaults (multicolor SVG) vtracer.convert_image_to_svg_py( image_path="input.jpg", out_path="output.svg" ) # Binary mode conversion (faster, good for line art) vtracer.convert_image_to_svg_py( image_path="drawing.png", out_path="drawing.svg", colormode='binary' ) # Full parameter example with all options vtracer.convert_image_to_svg_py( image_path="artwork.png", out_path="artwork.svg", colormode='color', # 'color' or 'binary' hierarchical='stacked', # 'stacked' or 'cutout' mode='spline', # 'spline', 'polygon', or 'none' filter_speckle=4, # Remove noise patches smaller than 4x4 px color_precision=6, # Use 6 significant bits per RGB channel layer_difference=16, # Color difference between gradient layers corner_threshold=60, # Min angle in degrees to detect corners length_threshold=4.0, # Segment subdivision threshold max_iterations=10, # Max smoothing iterations splice_threshold=45, # Min angle displacement for spline splicing path_precision=3 # Decimal places in SVG path strings ) # Example with error handling try: vtracer.convert_image_to_svg_py( image_path="logo.png", out_path="logo.svg", colormode='color', filter_speckle=10, color_precision=8 ) print("Conversion successful!") except Exception as e: print(f"Conversion failed: {e}") ``` -------------------------------- ### Python: Convert Raw Image Bytes to SVG Source: https://context7.com/visioncortex/vtracer/llms.txt Converts raw image bytes to an SVG string using various parameters for customization. Accepts image bytes, format, and numerous vectorization settings. Outputs an SVG string. ```python svg_string = vtracer.convert_raw_image_to_svg( img_bytes=img_bytes, img_format='jpg', colormode='color', hierarchical='stacked', mode='spline', filter_speckle=4, color_precision=6, layer_difference=16, corner_threshold=60, length_threshold=4.0, max_iterations=10, splice_threshold=45, path_precision=2 ) print(f"Generated SVG length: {len(svg_string)} characters") ``` -------------------------------- ### Python: Convert RGBA Pixels to SVG Source: https://context7.com/visioncortex/vtracer/llms.txt Converts RGBA pixel data to an SVG string, useful with libraries like PIL/Pillow and NumPy. It takes a list of RGBA tuples and the image dimensions. Supports customization via parameters and includes error handling for dimension mismatches. ```python import vtracer from PIL import Image # Convert from PIL Image img = Image.open("photo.jpg").convert('RGBA') width, height = img.size pixels = list(img.getdata()) # List of (r, g, b, a) tuples svg_string = vtracer.convert_pixels_to_svg( rgba_pixels=pixels, size=(width, height) ) # Save the result with open("output.svg", "w") as f: f.write(svg_string) # Process with custom parameters img = Image.open("artwork.png").convert('RGBA') pixels = list(img.getdata()) svg_string = vtracer.convert_pixels_to_svg( rgba_pixels=pixels, size=img.size, colormode='color', filter_speckle=10, color_precision=8, mode='spline' ) # Create synthetic image and convert from PIL import Image # Create a simple test pattern width, height = 100, 100 pixels = [] for y in range(height): for x in range(width): if (x // 10 + y // 10) % 2 == 0: pixels.append((255, 0, 0, 255)) # Red else: pixels.append((0, 0, 255, 255)) # Blue svg_string = vtracer.convert_pixels_to_svg( rgba_pixels=pixels, size=(width, height), colormode='color', mode='polygon' ) # Error handling for mismatched dimensions try: svg_string = vtracer.convert_pixels_to_svg( rgba_pixels=pixels, size=(50, 50), # Wrong size! colormode='binary' ) except Exception as e: print(f"Error: {e}") # Output: Length of rgba_pixels does not match given image size ``` -------------------------------- ### Convert Raw Image Bytes to SVG (Python) Source: https://github.com/visioncortex/vtracer/blob/master/cmdapp/vtracer/README.md This Python snippet shows how to convert raw image bytes directly into an SVG string using VTracer. This is useful when you have image data in memory, such as from a network request or file read operation, without needing to save it to disk first. The image format must be specified. ```python import vtracer # Convert from raw image bytes input_img_bytes: bytes = get_bytes() # e.g. reading bytes from a file or a HTTP request body svg_str: str = vtracer.convert_raw_image_to_svg(input_img_bytes, img_format='jpg') ``` -------------------------------- ### Python: convert_raw_image_to_svg Source: https://context7.com/visioncortex/vtracer/llms.txt Processes raw image bytes in memory to produce an SVG string without writing files to disk. Useful for web services and streaming applications where image data is received as a byte array. Returns the generated SVG content as a string. ```APIDOC ## POST /convert_raw_image_to_svg ### Description Converts raw image bytes to an SVG vector graphic using VTracer's Python bindings, optionally auto-detecting image format. ### Method POST ### Endpoint convert_raw_image_to_svg ### Parameters #### Request Body - **img_bytes** (binary) - Required - Raw image data as a byte array. - **img_format** (string) - Optional - Image format ('jpg', 'png', etc.). If omitted, the format is auto-detected. - **colormode** (string) - Optional - Color mode, either 'color' or 'binary'. - **hierarchical** (string) - Optional - Hierarchical clustering strategy, 'stacked' or 'cutout'. - **mode** (string) - Optional - Output mode, 'spline', 'polygon', or 'none'. - **filter_speckle** (integer) - Optional - Remove noise patches smaller than N×N pixels. - **color_precision** (integer) - Optional - Number of significant bits per RGB channel. - **corner_threshold** (integer) - Optional - Minimum angle in degrees to detect corners. - **length_threshold** (number) - Optional - Segment subdivision length threshold. - **path_precision** (integer) - Optional - Decimal places in SVG path strings. ### Request Example { "img_bytes": "", "img_format": "png", "colormode": "binary", "filter_speckle": 8 } ### Response #### Success Response (200) - **svg_content** (string) - The generated SVG markup. ### Response Example { "svg_content": "" } ``` -------------------------------- ### Python: Convert Raw Image Bytes to SVG with vtracer Source: https://context7.com/visioncortex/vtracer/llms.txt Process raw image bytes directly in memory without filesystem I/O using `vtracer.convert_raw_image_to_svg`. This is ideal for web services and streaming applications. The function accepts image bytes and optionally the image format, with support for various conversion parameters similar to the file-based conversion. ```python import vtracer import requests # Convert from HTTP request response = requests.get("https://example.com/image.jpg") img_bytes = response.content svg_string = vtracer.convert_raw_image_to_svg( img_bytes=img_bytes, img_format='jpg' ) # Save or process the SVG string with open("output.svg", "w") as f: f.write(svg_string) # Convert from file bytes with open("input.png", "rb") as f: img_bytes = f.read() svg_string = vtracer.convert_raw_image_to_svg( img_bytes=img_bytes, img_format='png', colormode='binary', filter_speckle=8 ) # Auto-detect format (slower but flexible) svg_string = vtracer.convert_raw_image_to_svg( img_bytes=img_bytes, img_format=None # Will guess format from content ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.