| Crates.io | img2avif |
| lib.rs | img2avif |
| version | 0.1.4 |
| created_at | 2025-04-17 11:11:00.943148+00 |
| updated_at | 2025-04-24 13:43:45.269772+00 |
| description | Convert images to AVIF format. |
| homepage | |
| repository | https://github.com/tnzzzhlp/img2avif |
| max_upload_size | |
| id | 1637527 |
| size | 4,086,002 |
Convert images to AVIF format.
This library provides functions to convert image data into the AVIF format.
use std::fs::File;
use img2avif::{convert, convert_with_quality_speed};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("path/to/your/image.png")?; // Supports PNG, JPEG, WebP, etc.
// Use default quality (85) and speed (6)
let avif_data = convert(file)?;
std::fs::write("output.avif", avif_data)?;
println!("Successfully converted image to AVIF!");
Ok(())
}
If you want to customize quality and speed:
use std::fs::File;
use img2avif::convert_with_quality_speed;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = File::open("path/to/your/image.jpg")?;
// quality: 0-100, speed: 0-10
let avif_data = convert_with_quality_speed(file, 90, 1)?;
std::fs::write("output.avif", avif_data)?;
Ok(())
}
See src/lib.rs for the function implementation and tests for more examples.
# Build the project
cargo build
# Run tests
cargo test
This project is licensed under the MIT License. See the Cargo.toml file for details.