webp-converter

Crates.iowebp-converter
lib.rswebp-converter
version0.1.0
sourcesrc
created_at2024-09-20 19:47:19.982279
updated_at2024-09-20 19:47:19.982279
descriptionA 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
repositoryhttps://github.com/csalmeida/webp-converter
max_upload_size
id1381737
size601,912
cristiano (csalmeida)

documentation

README

WebP Converter

A Rust library for converting image files to WebP format.

Features

  • Convert JPG, JPEG, PNG, and GIF images to WebP format
  • Batch conversion of images in a directory
  • Preserve directory structure during conversion
  • Error handling for conversion process

Installation

Add this to your Cargo.toml:

[dependencies]
webp_converter = "0.1.0"

Usage

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),
}

API

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.

License

This project is licensed under the MIT License.

Commit count: 1

cargo fmt