Skip to content

Commit

Permalink
feat: added options to jpeg codec
Browse files Browse the repository at this point in the history
  • Loading branch information
SalOne22 committed Mar 15, 2024
1 parent 032b050 commit ccd249c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/cli/codecs/jpeg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
use clap::Command;
use clap::{arg, value_parser, Command};

pub fn jpeg() -> Command {
Command::new("jpeg").about("Encode images into JPEG format")
Command::new("jpeg")
.alias("jpg")
.about("Encode images into JPEG format")
.args([
arg!(-q --quality <NUM> "Quality which the image will be encoded with")
.value_parser(value_parser!(u8).range(1..=100)),
arg!(--progressive "Set to use progressive encoding"),
])
}
14 changes: 12 additions & 2 deletions src/cli/pipeline.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::BTreeMap, fs::read, path::Path};

use clap::ArgMatches;
use zune_core::bytestream::ZByteReader;
use zune_core::{bytestream::ZByteReader, options::EncoderOptions};
use zune_image::{
codecs::{
farbfeld::FarbFeldEncoder, jpeg::JpegEncoder, jpeg_xl::JxlEncoder, png::PngEncoder,
Expand Down Expand Up @@ -119,7 +119,17 @@ pub fn encoder(matches: &ArgMatches) -> Result<(Box<dyn EncoderTrait>, &'static
match matches.subcommand() {
Some((name, matches)) => match name {
"farbfeld" => Ok((Box::new(FarbFeldEncoder::new()), "ff")),
"jpeg" => Ok((Box::new(JpegEncoder::new()), "jpg")),
"jpeg" => {
let options = EncoderOptions::default();

if let Some(quality) = matches.get_one::<u8>("quality") {
options.set_quality(*quality);
}

options.set_jpeg_encode_progressive(matches.get_flag("progressive"));

Ok((Box::new(JpegEncoder::new_with_options(options)), "jpg"))
}
"jpeg_xl" => Ok((Box::new(JxlEncoder::new()), "jxl")),
"png" => Ok((Box::new(PngEncoder::new()), "png")),
"ppm" => Ok((Box::new(PPMEncoder::new()), "ppm")),
Expand Down

0 comments on commit ccd249c

Please sign in to comment.