stitchy_core/
lib.rs

1//! Joining images together into a single image.
2//!
3//! Provides two processes, each configured using the builder pattern:
4//! - Selecting image files
5//! - Copying the (typically resized) contents of those files into a single output image
6//!
7//! The first process is performed by the [`ImageFiles`] struct and its associated builder pattern.
8//! Files are added either individually or from a directory.
9//!
10//! The second process is performed by the [`Stitch`] struct and its associated builder pattern.
11//! The configuration sets the output image size and layout of the output image. The output image
12//! is returned as an in-memory struct of type [`DynamicImage`], re-exported from the image crate
13//! (see the [image crate on crates.io](https://crates.io/crates/image)).
14//!
15//! # Examples
16//!
17//! ```
18//! // Select image files in current directory, take first 3 by alphabetic order on file name
19//! use stitchy_core::{ImageFiles, OrderBy, TakeFrom};
20//! let image_files = ImageFiles::builder()
21//!     .add_current_directory(vec!["..", "..", "images", "demo"]).unwrap()
22//!     .build().unwrap()
23//!     .sort_and_truncate_by(3, OrderBy::Alphabetic, TakeFrom::Start, false).unwrap();
24//!
25//! // Stitch images in a horizontal line, restricting the width to 1000 pixels
26//! use stitchy_core::{Stitch, AlignmentMode};
27//! let stitch = Stitch::builder()
28//!     .image_files(image_files).unwrap()
29//!     .width_limit(1000)
30//!     .alignment(AlignmentMode::Horizontal)
31//!     .stitch();
32//!
33//! assert!(stitch.is_ok());
34//! ```
35
36mod enums;
37mod files;
38mod stitch;
39
40#[cfg(test)]
41mod tests;
42
43/// Enums used for configuring the image stitching process
44pub use enums::{OrderBy, TakeFrom};
45
46/// Types used for loading files and passing them into the image stitching process
47pub use files::{
48    builder::ImageFilesBuilder,
49    image_types::ImageFiles,
50    path::{FilePath, FilePathWithMetadata},
51    raw::{RawBufferLocation, RawBufferProperties},
52    util::extension_formats,
53    FileLocation, FileProperties,
54};
55
56#[cfg(unix)]
57pub use files::fd::{OwnedRawFdLocation, OwnedRawFdProperties};
58
59/// Type used for running the image stitching process
60pub use stitch::{builder::StitchBuilder, AlignmentMode, Stitch};
61
62/// File utilities, used by the CLI crate
63pub mod util {
64    pub use crate::files::util::make_size_string;
65}
66
67/// Re-exports from the [image](https://crates.io/crates/image) crate
68pub mod image {
69    pub use image::{
70        codecs::{
71            gif::GifEncoder,
72            jpeg::JpegEncoder,
73            png::{CompressionType as PngCompressionType, FilterType as PngFilterType, PngEncoder}
74        },
75        imageops::FilterType,
76        metadata::Orientation,
77        DynamicImage, Frame, GenericImage, ImageDecoder,
78        ImageError, ImageFormat,
79    };
80}