| Crates.io | papercut |
| lib.rs | papercut |
| version | 0.1.2 |
| created_at | 2025-06-04 17:22:43.948175+00 |
| updated_at | 2025-06-04 17:29:26.964813+00 |
| description | A library and CLI tool for slicing and joining images. |
| homepage | https://github.com/orhanbalci/papercut |
| repository | https://github.com/orhanbalci/papercut |
| max_upload_size | |
| id | 1700678 |
| size | 383,420 |
Papercut is a Rust library and CLI tool for slicing and joining images. It provides functionality to split an image into tiles, save those tiles, and combine them back into a single image. This library is useful for image processing tasks such as creating image grids or splitting large images into smaller parts.
This project is a Rust translation of the Python project image_slicer by Sam Dobson. The functionality and structure of papercut are heavily inspired by the original project. Special thanks to Sam Dobson for creating the original library.
Add the following to your Cargo.toml to use Papercut as a library:
[dependencies]
papercut = "0.1.2"
use papercut::slice;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let tiles = slice("image.png", Some(4), None, None, false)?;
println!("Generated {} tiles.", tiles.len());
Ok(())
}
use papercut::{save_tiles, get_basename};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let tiles = slice("image.png", Some(4), None, None, false)?;
save_tiles(&mut tiles, &get_basename("image.png"), Some(std::path::Path::new("./output")), "png")?;
println!("Tiles saved successfully!");
Ok(())
}
use papercut::join;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let tiles = slice("image.png", Some(4), None, None, false)?;
let combined_image = join(&tiles, 0, 0)?;
combined_image.save("combined_image.png")?;
println!("Image combined successfully!");
Ok(())
}
Papercut includes a CLI tool for slicing images. To use it, build the binary and run it:
cargo run --example slice-image -- --image image.png --num-tiles 4 --dir ./output --format png
Arguments
Slice an Image into 4 Tiles
cargo run --example slice-image -- --image image.png --num-tiles 4 --dir ./output --format png
Slice an Image into a Custom Grid
cargo run --example slice-image -- --image image.png --rows 2 --columns 2 --dir ./output --format png
Combine Tiles Back into a Single Image
use papercut::{open_images_in, join};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let tiles = open_images_in(Path::new("./output"))?;
let combined_image = join(&tiles, 0, 0)?;
combined_image.save("combined_image.png")?;
println!("Image combined successfully!");
Ok(())
}
This project is licensed under the MIT License. See the LICENSE file for details.