img_comp 1.0.3

jpg, png 图片压缩
Documentation
  • Coverage
  • 60%
    6 out of 10 items documented0 out of 0 items with examples
  • Size
  • Source code size: 37.31 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 689.22 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 46s Average build duration of successful builds.
  • all releases: 46s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • zomem

图片压缩

使用的 rimage 压缩库 png、jpg的压缩率在50%左右,效果很不错。

使用方法

1.通过指定输入输出路径来压缩

use img_comp::{ImgCompConfig, ImgType, img_comp_with_path};
let config = ImgCompConfig {
    img_type: ImgType::Jpg,
    resize_width: None,
    quality: 80,
};
img_comp_with_path("1.jpg", "1_mini.jpg", &config).unwrap();
let config = ImgCompConfig {
    img_type: ImgType::Jpg,
    resize_width: Some(200),
    quality: 80,
};
img_comp_with_path("2.png", "2_mini.png", &config).unwrap();

2.图片buffer数据来压缩,返回也为buffer数据。

use img_comp::{ImgCompConfig, ImgType, img_comp_with_buf};
let config = ImgCompConfig {
    img_type: ImgType::Jpg,
    resize_width: None,
    quality: 80,
};
let buf = img_comp_with_buf(buffer, &config).unwrap();
println!("压缩后的数据 {}", buf.len());