Crates.io | converter_buddy |
lib.rs | converter_buddy |
version | 0.2.1 |
source | src |
created_at | 2022-06-18 23:57:26.736825 |
updated_at | 2023-04-24 17:53:22.621148 |
description | File format conversion library. Provides conversion utilities between files with different formats. |
homepage | https://github.com/attilio-oliva/converter-buddy |
repository | https://github.com/attilio-oliva/converter-buddy |
max_upload_size | |
id | 608745 |
size | 222,211 |
Converter Buddy provides a simple to use way to convert file from a format to another.
Currently only the most popular image formats are supported, but the goal is to extend to documents, audio and video formats.
ConvertibleFile is a conversion utility wrapper for std::fs::File:
let src_path = "tests/assets/test.png";
let file = ConvertibleFile::new(src_path);
let format = file.format().expect("No format found");
let target_format = Format::Jpeg;
println!("Found source format: {}", format);
println!("Converting to {} format", target_format);
match file.convert(target_format) {
Ok(_) => println!("Conversion successful"),
Err(e) => println!("Conversion failed: {:?}", e),
}
You can use the underneath converters if you want to use bytes vectors instead of std::fs primitives:
fn get_input_data() -> Vec<u8> {
...
}
fn main() {
let input = get_input_data();
let mut output = Vec::<u8>::new();
PngConverter.process(&input, &mut output, JpegConfig::default()).expect("Conversion error");
// or in a more generic way
let source_format = Format::Png;
let target_format = Format::Jpeg;
let converter = Converter::try_from(source_format).expect("This format cannot be converted");
converter.process(&input, &mut output, target_format.into()).expect("Conversion error");
// use output ...
}
From\To | PNG | JPEG | BMP | TIFF | GIF | SVG | WEBP | |
---|---|---|---|---|---|---|---|---|
PNG | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ |
JPEG | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ |
BMP | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ |
TIFF | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ |
GIF | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ |
SVG | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ |
WEBP | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |