| Crates.io | webp-screenshot-rust |
| lib.rs | webp-screenshot-rust |
| version | 1.0.0 |
| created_at | 2025-10-26 13:27:25.698666+00 |
| updated_at | 2025-10-26 13:27:25.698666+00 |
| description | High-performance cross-platform screenshot capture library with WebP encoding, hardware acceleration, and multi-monitor support for Windows, macOS, and Linux |
| homepage | |
| repository | https://github.com/KCuppens/webp-screenshot-rust |
| max_upload_size | |
| id | 1901397 |
| size | 490,703 |
A high-performance, cross-platform screenshot capture library with WebP encoding, written in pure Rust.
Add to your Cargo.toml:
[dependencies]
webp-screenshot-rust = "1.0"
use webp_screenshot_rust::WebPScreenshot;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Capture primary display
let mut screenshot = WebPScreenshot::new()?;
let result = screenshot.capture_display(0)?;
result.save("screenshot.webp")?;
println!("Screenshot saved! Size: {} KB", result.size() / 1024);
Ok(())
}
use webp_screenshot_rust::{WebPScreenshot, CaptureConfig, WebPConfig};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = CaptureConfig {
webp_config: WebPConfig::high_quality(),
include_cursor: true,
use_hardware_acceleration: true,
..Default::default()
};
let mut screenshot = WebPScreenshot::with_config(config)?;
let result = screenshot.capture_display(0)?;
println!("Compression ratio: {:.1}%",
result.metadata.compression_ratio() * 100.0);
Ok(())
}
use webp_screenshot_rust::WebPScreenshot;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut screenshot = WebPScreenshot::new()?;
// Capture all displays
let results = screenshot.capture_all_displays();
for (index, result) in results.iter().enumerate() {
if let Ok(capture) = result {
capture.save(&format!("display_{}.webp", index))?;
}
}
Ok(())
}
Benchmarks on Windows 11 (Intel i7-12700K, 32GB RAM):
| Resolution | Capture Time | Encoding Time | WebP Size | Compression |
|---|---|---|---|---|
| 1920x1080 | 12ms | 25ms | 145 KB | 97.3% |
| 2560x1440 | 18ms | 38ms | 256 KB | 97.2% |
| 3840x2160 | 28ms | 65ms | 512 KB | 97.5% |
| Metric | Node.js/C++ | Rust | Improvement |
|---|---|---|---|
| Capture Time | 45ms | 12ms | 73% faster |
| Memory Usage | 150MB | 45MB | 70% less |
| Binary Size | 25MB | 3.5MB | 86% smaller |
| WebP Encoding | 95ms | 25ms | 74% faster |
// Fast encoding, lower quality
let config = WebPConfig::fast();
// Balanced quality/speed
let config = WebPConfig::balanced();
// High quality, slower encoding
let config = WebPConfig::high_quality();
// Lossless compression
let config = WebPConfig::lossless();
let config = WebPConfig {
quality: 90, // 0-100
method: 4, // 0-6 (compression effort)
lossless: false,
segments: 4, // 1-4
sns_strength: 50, // 0-100
filter_strength: 60, // 0-100
alpha_quality: 100, // 0-100
pass: 1, // 1-10
thread_count: 0, // 0 = auto
..Default::default()
};
Optional cargo features:
[dependencies]
webp-screenshot-rust = {
version = "1.0",
features = ["simd", "parallel", "wayland", "gpu"]
}
simd: Enable SIMD optimizations (default)parallel: Enable parallel processing (default)wayland: Linux Wayland supportgpu: GPU acceleration (experimental)c-api: Build C API for FFI# Standard build
cargo build --release
# With all features
cargo build --release --all-features
# Run examples
cargo run --example simple_capture
cargo run --example multi_display
cargo run --example streaming
The library includes an intelligent memory pool that:
let screenshot = WebPScreenshot::new()?;
let stats = screenshot.memory_stats();
println!("Buffer hit rate: {:.1}%", stats.hit_rate());
Comprehensive error types with recovery information:
match screenshot.capture_display(0) {
Ok(result) => { /* success */ },
Err(CaptureError::PermissionDenied(_)) => {
// Handle permission error
},
Err(e) if e.is_recoverable() => {
// Retry capture
},
Err(e) => {
// Fatal error
}
}
fast() preset for real-time captureContributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT License - see LICENSE for details.
For users migrating from the Node.js webp-screenshot package:
See MIGRATION.md for detailed migration guide.