| Crates.io | thumbnailify |
| lib.rs | thumbnailify |
| version | 0.1.4 |
| created_at | 2025-02-27 08:49:14.150989+00 |
| updated_at | 2025-02-28 00:52:49.221077+00 |
| description | A Rust library for generating and caching thumbnails using the GNOME thumbnailer approach. |
| homepage | |
| repository | https://github.com/luigi311/thumbnailify |
| max_upload_size | |
| id | 1571488 |
| size | 116,134 |
Thumbnailify is a Rust library for generating and caching thumbnails for image files using the GNOME thumbnailer approach. It supports multiple MIME types, ensures thumbnails are up to date by comparing metadata, and leverages external commands (with optional sandboxing via Bubblewrap) for secure thumbnail generation.
~/.cache) and checks if the cached thumbnail is up to date.thiserror crate to handle errors from various sources.Add the following to your Cargo.toml:
[dependencies]
thumbnailify = "0.1"
use thumbnailify::{generate_thumbnail, ThumbnailSize, ThumbnailError};
use std::path::Path;
fn main() -> Result<(), ThumbnailError> {
// Specify the path to your source image.
let image_path = Path::new("path/to/your/image.png");
// Generate a thumbnail of "Normal" size.
let thumbnail_path = generate_thumbnail(image_path, ThumbnailSize::Normal)?;
println!("Thumbnail generated at: {:?}", thumbnail_path);
Ok(())
}
error Module:
Defines a unified error type (ThumbnailError) that wraps errors from libraries such as image, std::io, ini, tempfile, shell_words, and png.
file Module:
Contains helpers for determining cache directories, writing thumbnails (or failure markers), and converting file paths to URIs.
hash Module:
Provides an MD5-based function to compute a hash from the image file's URI, ensuring a unique thumbnail name.
sizes Module:
Offers predefined thumbnail sizes (Small, Normal, Large, XLarge, XXLarge) that correspond to maximum dimensions in pixels.
thumbnailer Module:
Implements the main logic to generate thumbnails:
.thumbnailer file.The library includes tests to verify core functionality. Run the tests using:
cargo test
Contributions are welcome! If you have suggestions, encounter any issues, or would like to add features, please open an issue or submit a pull request.