Crates.io | webp-converter |
lib.rs | webp-converter |
version | 0.1.0 |
source | src |
created_at | 2024-09-20 19:47:19.982279 |
updated_at | 2024-09-20 19:47:19.982279 |
description | A library for converting image files (JPG, JPEG, PNG, GIF) to WebP format, providing functionality for batch conversion with directory structure preservation and error handling. |
homepage | |
repository | https://github.com/csalmeida/webp-converter |
max_upload_size | |
id | 1381737 |
size | 601,912 |
A Rust library for converting image files to WebP format.
Add this to your Cargo.toml
:
[dependencies]
webp_converter = "0.1.0"
Basic usage:
use webp_converter::WebPConverter;
let converter = WebPConverter::new("path/to/source", "path/to/output");
converter.convert().unwrap();
Converting a specific directory:
use webp_converter::WebPConverter;
use std::path::Path;
let source = Path::new("/home/user/images");
let output = Path::new("/home/user/webp_images");
let converter = WebPConverter::new(source.to_str().unwrap(), output.to_str().unwrap());
converter.convert().unwrap();
Handling conversion errors:
use webp_converter::WebPConverter;
let converter = WebPConverter::new("path/to/source", "path/to/output");
match converter.convert() {
Ok(_) => println!("All images converted successfully"),
Err(e) => eprintln!("Error during conversion: {}", e),
}
WebPConverter::new(source_dir: &str, output_dir: &str) -> Self
Creates a new WebPConverter
instance with the specified source and output directories.
WebPConverter::convert(&self) -> Result<(), Box<dyn std::error::Error>>
Converts all supported image files in the source directory to WebP format and saves them in the output directory.
This project is licensed under the MIT License.