#file-format #convert #extension

converter_buddy

File format conversion library. Provides conversion utilities between files with different formats.

4 releases

0.2.1 Apr 24, 2023
0.2.0 Apr 21, 2023
0.1.2 Jul 3, 2022
0.1.1 Jun 20, 2022
0.1.0 Jun 18, 2022

#676 in Images

Download history 11/week @ 2023-11-20 10/week @ 2023-11-27 1/week @ 2023-12-04 40/week @ 2023-12-11 213/week @ 2023-12-18 16/week @ 2023-12-25 63/week @ 2024-01-01 57/week @ 2024-01-08 15/week @ 2024-01-15 96/week @ 2024-01-22 8/week @ 2024-02-12 15/week @ 2024-02-19 26/week @ 2024-02-26 5/week @ 2024-03-04

54 downloads per month

MIT license

74KB
1.5K SLoC

Converter Buddy

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.

Basic usage

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 ...
}

Compatibility

From\To PNG JPEG BMP TIFF GIF SVG WEBP PDF
PNG
JPEG
BMP
TIFF
GIF
SVG
WEBP

Dependencies

~18MB
~173K SLoC