makeshot.ai
A Rust crate designed to simplify the process of capturing, processing, and sharing screenshots programmatically. This library provides a streamlined API for automating screenshot workflows in your applications.
Installation
To include makeshot.ai in your project, add the following to your Cargo.toml file:
toml
[dependencies]
makeshot_ai = "0.1.0" # Replace with the latest version
Usage Examples
Here are a few examples demonstrating how to use the makeshot.ai crate:
1. Capturing a specific window: rust use makeshot_ai::capture; use makeshot_ai::Target;
fn main() -> Result<(), Box> { // Target a window by its title. Replace "My Application" with the actual window title. let target = Target::WindowName("My Application".to_string());
// Capture the specified window and save it as a PNG.
capture(&target, "window_capture.png")?;
println!("Window captured and saved to window_capture.png");
Ok(())
}
2. Capturing the entire primary screen: rust use makeshot_ai::capture; use makeshot_ai::Target;
fn main() -> Result<(), Box> { // Capture the primary screen. let target = Target::PrimaryScreen;
// Capture the screen and save it as a JPEG with a specified quality.
capture(&target, "screen_capture.jpg")?;
println!("Screen captured and saved to screen_capture.jpg");
Ok(())
}
3. Capturing a region of the screen: rust use makeshot_ai::capture; use makeshot_ai::Target; use makeshot_ai::Region;
fn main() -> Result<(), Box> { // Define the region to capture (x, y, width, height). let region = Region { x: 100, y: 100, width: 800, height: 600, };
// Capture the specified region of the primary screen.
let target = Target::Region(region);
// Capture the region and save it as a PNG.
capture(&target, "region_capture.png")?;
println!("Region captured and saved to region_capture.png");
Ok(())
}
4. Capturing and Converting to Base64: rust use makeshot_ai::capture_to_base64; use makeshot_ai::Target;
fn main() -> Result<(), Box> { // Capture the primary screen and encode it as a Base64 string. let target = Target::PrimaryScreen; let base64_string = capture_to_base64(&target)?;
println!("Screen captured and encoded to Base64: {}", &base64_string[..100]); // Print first 100 chars
Ok(())
}
5. Handling Errors Gracefully: rust use makeshot_ai::capture; use makeshot_ai::Target;
fn main() { let target = Target::WindowName("NonExistentWindow".to_string());
match capture(&target, "attempted_capture.png") {
Ok(_) => println!("Capture successful (unexpected)."),
Err(e) => println!("Capture failed: {}", e),
}
}
Feature Summary
- Targeted Capture: Capture specific windows, the primary screen, or defined regions.
- Output Formats: Save screenshots in various image formats (PNG, JPEG, etc.).
- Base64 Encoding: Capture directly to Base64 encoded strings for easy embedding in web applications.
- Error Handling: Robust error handling for common issues like missing windows or incorrect permissions.
- Cross-Platform Support: Designed to work seamlessly across different operating systems (Windows, macOS, Linux).
License
MIT
This crate is part of the makeshot.ai ecosystem. For advanced features and enterprise-grade tools, visit: https://makeshot.ai/