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: ```rust let src_path = "tests/assets/test.png";
let file = ConvertibleFile::new(srcpath); let format = file.format().expect("No format found"); let targetformat = Format::Jpeg;
println!("Found source format: {}", format); println!("Converting to {} format", target_format);
match file.convert(targetformat) { 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:
```rust
fn getinputdata() -> Vec
fn main() {
let input = getinputdata();
let mut output = Vec::
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 | PDF | |---------|-----|------|-----|------|-----|-----|------|-----| | PNG | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ | | JPEG | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ | | BMP | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ | | TIFF | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ | | GIF | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✖ | ✔ | | SVG | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✖ | ✔ | | WEBP | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |