Skip to content

Commit

Permalink
Added optimize from memory
Browse files Browse the repository at this point in the history
  • Loading branch information
SalOne22 committed Jun 27, 2023
1 parent 45559da commit 202cba0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ pub use decoder::Decoder;
pub use encoder::Encoder;
pub use memory_decoder::MemoryDecoder;
pub use optimize::optimize;
pub use optimize::optimize_from_memory;
14 changes: 13 additions & 1 deletion src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{error::Error, fs, path};

use log::info;

use crate::{Config, Decoder, Encoder};
use crate::{image::InputFormat, Config, Decoder, Encoder, MemoryDecoder};

/// Optimizes one image with provided config
pub fn optimize(image_path: &path::Path, config: &Config) -> Result<Vec<u8>, Box<dyn Error>> {
Expand All @@ -15,3 +15,15 @@ pub fn optimize(image_path: &path::Path, config: &Config) -> Result<Vec<u8>, Box

Ok(e.encode()?)
}

/// Optimizes one image from memory with provided config
pub fn optimize_from_memory(
data: &[u8],
input_format: InputFormat,
config: &Config,
) -> Result<Vec<u8>, Box<dyn Error>> {
let d = MemoryDecoder::new(data, input_format);
let e = Encoder::new(config, d.decode()?);

Ok(e.encode()?)
}

0 comments on commit 202cba0

Please sign in to comment.