Fix features with compress to size
This commit is contained in:
parent
7a02953cfa
commit
1797b37adf
29
Cargo.toml
29
Cargo.toml
|
@ -1,12 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "libcaesium"
|
name = "libcaesium"
|
||||||
version = "0.12.0"
|
version = "0.12.1"
|
||||||
authors = ["Matteo Paonessa <matteo.paonessa@gmail.com>"]
|
authors = ["Matteo Paonessa <matteo.paonessa@gmail.com>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
categories = ["multimedia::images"]
|
categories = ["multimedia::images"]
|
||||||
keywords = [
|
keywords = [
|
||||||
"compression",
|
"compression",
|
||||||
"library",
|
|
||||||
"jpeg",
|
"jpeg",
|
||||||
"png",
|
"png",
|
||||||
"gif",
|
"gif",
|
||||||
|
@ -21,19 +20,6 @@ homepage = "https://github.com/Lymphatus/libcaesium"
|
||||||
repository = "https://github.com/Lymphatus/libcaesium"
|
repository = "https://github.com/Lymphatus/libcaesium"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
mozjpeg-sys = { version = "1.0", optional = true }
|
|
||||||
oxipng = { version = "8.0", optional = true }
|
|
||||||
libc = "0.2"
|
|
||||||
gifsicle = { version = "1.92.5", optional = true }
|
|
||||||
webp = { version = "0.2.2", optional = true }
|
|
||||||
infer = "0.13.0"
|
|
||||||
image = { version = "0.24.6", default-features = false, features = ["jpeg", "png", "webp", "gif"] }
|
|
||||||
img-parts = "0.3"
|
|
||||||
bytes = "1.1"
|
|
||||||
lodepng = { version = "3.7", optional = true }
|
|
||||||
imagequant = {version = "4.1", optional = true}
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["jpg", "png", "webp", "gif"]
|
default = ["jpg", "png", "webp", "gif"]
|
||||||
jpg = ["dep:mozjpeg-sys"]
|
jpg = ["dep:mozjpeg-sys"]
|
||||||
|
@ -41,6 +27,19 @@ png = ["dep:oxipng", "dep:lodepng", "dep:imagequant"]
|
||||||
webp = ["dep:webp"]
|
webp = ["dep:webp"]
|
||||||
gif = ["dep:gifsicle"]
|
gif = ["dep:gifsicle"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
mozjpeg-sys = { version = "1.0", optional = true }
|
||||||
|
oxipng = { version = "8.0", optional = true }
|
||||||
|
libc = "0.2"
|
||||||
|
gifsicle = { version = "1.92.5", optional = true }
|
||||||
|
webp = { version = "0.2.2", optional = true }
|
||||||
|
infer = "0.15.0"
|
||||||
|
image = { version = "0.24.6", default-features = false, features = ["jpeg", "png", "webp", "gif"] }
|
||||||
|
img-parts = "0.3"
|
||||||
|
bytes = "1.1"
|
||||||
|
lodepng = { version = "3.7", optional = true }
|
||||||
|
imagequant = {version = "4.1", optional = true}
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
dssim = "3.2.0"
|
dssim = "3.2.0"
|
||||||
kamadak-exif = "0.5.4"
|
kamadak-exif = "0.5.4"
|
||||||
|
|
|
@ -175,7 +175,7 @@ Valid values for `jpeg_chroma_subsampling` are [444, 422, 420, 411]. Any other v
|
||||||
Binaries not available. Please refer to the compilation section below.
|
Binaries not available. Please refer to the compilation section below.
|
||||||
|
|
||||||
## Compilation and Installation
|
## Compilation and Installation
|
||||||
Compilation is available for all supported platforms: Windows, MacOS and Linux.
|
Compilation is available for all supported platforms: Windows, macOS and Linux.
|
||||||
|
|
||||||
```
|
```
|
||||||
cargo build --release
|
cargo build --release
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub struct CCSResult {
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
pub struct JpegParameters {
|
pub struct JpegParameters {
|
||||||
pub quality: u32,
|
pub quality: u32,
|
||||||
pub chroma_subsampling: jpeg::ChromaSubsampling
|
pub chroma_subsampling: ChromaSubsampling
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -80,7 +80,7 @@ pub struct CSParameters {
|
||||||
pub fn initialize_parameters() -> CSParameters {
|
pub fn initialize_parameters() -> CSParameters {
|
||||||
let jpeg = JpegParameters {
|
let jpeg = JpegParameters {
|
||||||
quality: 80,
|
quality: 80,
|
||||||
chroma_subsampling: jpeg::ChromaSubsampling::Auto
|
chroma_subsampling: ChromaSubsampling::Auto
|
||||||
};
|
};
|
||||||
|
|
||||||
let png = PngParameters {
|
let png = PngParameters {
|
||||||
|
@ -247,14 +247,17 @@ pub fn compress_to_size(
|
||||||
}
|
}
|
||||||
|
|
||||||
let compressed_file = match file_type {
|
let compressed_file = match file_type {
|
||||||
|
#[cfg(feature = "jpg")]
|
||||||
SupportedFileTypes::Jpeg => {
|
SupportedFileTypes::Jpeg => {
|
||||||
parameters.jpeg.quality = quality;
|
parameters.jpeg.quality = quality;
|
||||||
jpeg::compress_to_memory(in_file.clone(), parameters)? //TODO clone
|
jpeg::compress_to_memory(in_file.clone(), parameters)? //TODO clone
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "png")]
|
||||||
SupportedFileTypes::Png => {
|
SupportedFileTypes::Png => {
|
||||||
parameters.png.quality = quality;
|
parameters.png.quality = quality;
|
||||||
png::compress_to_memory(in_file.clone(), parameters)? //TODO clone
|
png::compress_to_memory(in_file.clone(), parameters)? //TODO clone
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "webp")]
|
||||||
SupportedFileTypes::WebP => {
|
SupportedFileTypes::WebP => {
|
||||||
parameters.webp.quality = quality;
|
parameters.webp.quality = quality;
|
||||||
webp::compress_to_memory(in_file.clone(), parameters)? //TODO clone
|
webp::compress_to_memory(in_file.clone(), parameters)? //TODO clone
|
||||||
|
|
|
@ -88,7 +88,7 @@ fn extract_exif(path: &Path) -> HashMap<String, String> {
|
||||||
for f in exif.fields() {
|
for f in exif.fields() {
|
||||||
exif_map.insert(
|
exif_map.insert(
|
||||||
format!("{}", f.tag),
|
format!("{}", f.tag),
|
||||||
f.display_value().to_string() as String,
|
f.display_value().to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue