simple_gal/imaging/mod.rs
1//! Image processing — pure Rust, zero external dependencies.
2//!
3//! This module handles all image manipulation in Simple Gal: reading dimensions,
4//! extracting IPTC metadata, generating responsive sizes, and creating thumbnails.
5//! Everything uses pure Rust crates (`image`, `rav1e`) — no ImageMagick, no FFmpeg,
6//! no system libraries. This is a deliberate choice: the binary is fully self-contained,
7//! so it works on any machine without installing prerequisites.
8//!
9//! ## Operation Table
10//!
11//! | Operation | Implementation |
12//! |---|---|
13//! | **Identify** (dimensions) | `image::image_dimensions` |
14//! | **IPTC metadata** | Custom parser (`iptc_parser`) — reads JPEG APP13 + TIFF IFD |
15//! | **Resize → AVIF** | Lanczos3 resampling + rav1e AVIF encoder |
16//! | **Thumbnail** | `resize_to_fill` (center crop) + optional `unsharpen` |
17//!
18//! ## Architecture: Backend Trait Pattern
19//!
20//! The module separates *what* to do from *how* to do it using the [`ImageBackend`] trait:
21//!
22//! - **[`calculations`]** — Pure functions for dimension math (aspect ratios, responsive
23//! sizes). Fully unit-testable with no I/O.
24//! - **[`params`]** — Data structs (`ResizeParams`, `ThumbnailParams`) describing operations.
25//! - **[`backend`]** — The [`ImageBackend`] trait defining identify/resize/thumbnail.
26//! Includes a `MockBackend` (behind `#[cfg(test)]`) for fast, deterministic tests.
27//! - **[`rust_backend`]** — [`RustBackend`], the production implementation using `image` + `rav1e`.
28//! - **[`operations`]** — High-level functions (`create_responsive_images`, `create_thumbnail`)
29//! that combine calculations + backend. Accept `&dyn ImageBackend` for testability.
30
31pub mod backend;
32pub mod calculations;
33pub(crate) mod iptc_parser;
34pub mod operations;
35pub mod params;
36pub mod rust_backend;
37
38#[cfg(test)]
39pub use backend::Dimensions;
40pub use backend::{BackendError, ImageBackend};
41pub use calculations::calculate_thumbnail_dimensions;
42pub use operations::{
43 ResponsiveConfig, ThumbnailConfig, create_responsive_images, create_thumbnail, get_dimensions,
44};
45pub use params::{Quality, Sharpening};
46pub use rust_backend::{RustBackend, supported_input_extensions};