| Crates.io | embroidery_tools |
| lib.rs | embroidery_tools |
| version | 0.2.0 |
| created_at | 2025-03-29 07:17:15.689075+00 |
| updated_at | 2025-08-09 18:38:17.722307+00 |
| description | Tools for handling embroidery patterns, formats, and operations with PES/PEC file support |
| homepage | https://github.com/Wandalen/cgtools/tree/master/module/helper/embroidery_tools |
| repository | https://github.com/Wandalen/cgtools |
| max_upload_size | |
| id | 1610888 |
| size | 116,119 |
Comprehensive embroidery file format support for reading and writing stitch patterns
A robust library for handling embroidery files in various formats. Supports reading, writing, and manipulating stitch patterns for embroidery machines and design software. Built with precision and reliability for professional embroidery workflows.
Add to your Cargo.toml:
embroidery_tools = { workspace = true }
use embroidery_tools::*;
fn read_pattern() -> Result<(), Box<dyn std::error::Error>> {
// Read PES file
let pattern = pes::read_file("design.pes")?;
println!("Pattern info:");
println!(" Stitches: {}", pattern.stitch_count());
println!(" Colors: {}", pattern.color_count());
println!(" Size: {}x{} mm", pattern.width(), pattern.height());
// Access stitch data
for stitch in pattern.stitches() {
match stitch.command {
StitchCommand::Normal => {
println!("Stitch at ({}, {})", stitch.x, stitch.y);
},
StitchCommand::Jump => {
println!("Jump to ({}, {})", stitch.x, stitch.y);
},
StitchCommand::ColorChange => {
println!("Color change at ({}, {})", stitch.x, stitch.y);
},
}
}
Ok(())
}
use embroidery_tools::*;
fn create_pattern() -> Result<(), Box<dyn std::error::Error>> {
// Create new pattern
let mut pattern = EmbroideryPattern::new();
// Add color palette
pattern.add_color(Color::rgb(255, 0, 0)); // Red
pattern.add_color(Color::rgb(0, 255, 0)); // Green
pattern.add_color(Color::rgb(0, 0, 255)); // Blue
// Add stitches
pattern.add_stitch(Stitch::normal(0, 0));
pattern.add_stitch(Stitch::normal(100, 0));
pattern.add_stitch(Stitch::normal(100, 100));
pattern.add_stitch(Stitch::color_change(100, 100));
pattern.add_stitch(Stitch::normal(0, 100));
pattern.add_stitch(Stitch::normal(0, 0));
// Write to PES format
pes::write_file(&pattern, "output.pes", PesVersion::V6)?;
// Write to PEC format
pec::write_file(&pattern, "output.pec")?;
Ok(())
}
| Format | Read | Write | Versions | Description |
|---|---|---|---|---|
| PES | โ | โ | v1, v6 | Brother/Babylock embroidery format |
| PEC | โ | โ | - | Brother embroidery machine format |
| Type | Description | Use Case |
|---|---|---|
EmbroideryPattern |
Complete pattern data | Pattern manipulation and storage |
Stitch |
Individual stitch point | Building stitch sequences |
Color |
Thread color information | Color palette management |
StitchCommand |
Stitch type/instruction | Machine command interpretation |
// Pattern analysis
let bounds = pattern.bounds();
let stitch_count = pattern.stitch_count();
let color_count = pattern.color_count();
// Pattern modification
pattern.scale(2.0); // Scale by factor
pattern.translate(50, 25); // Move pattern
pattern.rotate(std::f32::consts::PI); // Rotate pattern
pattern.optimize(); // Remove redundant stitches
The library handles the binary formats according to official specifications:
// RGB color specification
let red = Color::rgb(255, 0, 0);
// Palette-based colors
let thread = Color::palette_index(5);
// Named thread colors (if supported by format)
let rayon = Color::thread("Madeira Rayon 1147");
// Convert vector graphics to embroidery
use embroidery_tools::*;
fn vectorize_to_embroidery(svg_path: &str) -> Result<EmbroideryPattern, Box<dyn std::error::Error>> {
// Parse SVG and convert to stitch pattern
let mut pattern = EmbroideryPattern::new();
// Add stitches following vector paths
// (Implementation would depend on vector processing library)
Ok(pattern)
}
// Convert multiple files
use embroidery_tools::*;
use std::fs;
fn convert_directory(input_dir: &str, output_dir: &str) -> Result<(), Box<dyn std::error::Error>> {
for entry in fs::read_dir(input_dir)? {
let path = entry?.path();
if path.extension() == Some("pes".as_ref()) {
let pattern = pes::read_file(&path)?;
let output_path = format!("{}/{}.pec", output_dir, path.file_stem().unwrap().to_str().unwrap());
pec::write_file(&pattern, &output_path)?;
}
}
Ok(())
}