#image #join #directory

stitchy-core

Library to combine multiple image files into a single image

6 releases

0.1.5 Mar 7, 2025
0.1.4 Feb 12, 2025
0.1.3 Jan 12, 2025
0.1.2 May 11, 2024
0.1.0 Apr 29, 2023

#1046 in Images

Download history 6/week @ 2024-12-04 13/week @ 2024-12-11 122/week @ 2025-01-08 38/week @ 2025-01-15 5/week @ 2025-01-22 10/week @ 2025-02-05 139/week @ 2025-02-12 17/week @ 2025-02-19 16/week @ 2025-02-26 123/week @ 2025-03-05 6/week @ 2025-03-12

147 downloads per month
Used in stitchy

MIT license

66KB
1.5K SLoC

Stitchy Core

example workflow Crates.io

Joins multiple existing image files into a single output. Design features include:

  • Builder structures for applying common usage
  • Collecting source files individually by path, or in bulk from directories
  • Re-exports from the image crate, on which this crate relies heavily and the output is returned as an image::DynamicImage, which is re-exported from this crate for convenience.

See the root project overview for an overview of the Stitchy ecosystem.

Typical Usage

To take the 3 most recently updated files in the current directory, ordering them oldest to newest, and writing the output to the current directory, run:

use stitchy_core::{ImageFiles, FilePathWithMetadata, OrderBy, TakeFrom, Stitch, AlignmentMode, image::ImageOutputFormat};
use std::fs::File;
use std::path::PathBuf;

fn run_stitch() -> Result<(), String> {
    let number_of_files = 3;

    let image_contents = ImageFiles::<FilePathWithMetadata>::builder()
        .add_current_directory(vec![])?
        .build()?
        .sort_and_truncate_by(
            number_of_files,
            OrderBy::Latest,
            TakeFrom::Start,
            false
        )?
        .into_image_contents(true)?;

    let output = Stitch::builder()
        .images(image_contents)
        .alignment(AlignmentMode::Horizontal)
        .stitch()?;

    let mut file_path: PathBuf = std::env::current_dir().unwrap();
    file_path.push("stitch.png");
    let mut file_writer = File::create(file_path).unwrap();
    output.write_to(&mut file_writer, ImageOutputFormat::Png)
        .map_err(|_| "Image could not be written.".to_owned())?;
    Ok(())
}

See these examples for more complicated real-world usage:

Dependencies

~4MB
~76K SLoC