diff --git a/docker/imageflow_bench_ubuntu20/bench.sh b/docker/imageflow_bench_ubuntu20/bench.sh index c7bd281cf..43120c724 100644 --- a/docker/imageflow_bench_ubuntu20/bench.sh +++ b/docker/imageflow_bench_ubuntu20/bench.sh @@ -23,8 +23,8 @@ cd bench_in if [[ "$1" == "thumbnail" ]]; then # shellcheck disable=SC2016 - hyperfine --export-markdown results.md \ - 'parallel "$HOME/bin/imageflow_tool v0.1/ir4 --in {} --out ../bench_out/{.}_200x200.jpg --command width=\"200&height=200&mode=max&quality=90&jpeg.turbo=true\"" ::: *.jpg' \ + hyperfine --export-markdown results.md --warmup 1 \ + 'parallel "$HOME/bin/imageflow_tool v0.1/ir4 --in {} --out ../bench_out/{.}_200x200.jpg --command width=200&height=200&quality=90" ::: *.jpg' \ 'parallel "vipsthumbnail --linear --size=200x200 --output=../bench_out/{.}_vips_200x200.jpg[Q=90,strip] {}" ::: *.jpg' \ 'parallel "gm convert {} -set colorspace sRGB -colorspace RGB -filter Mitchell -resize 200x200 -colorspace sRGB -quality 90 ../bench_out/{.}_gm_200x200.jpg" ::: *.jpg' \ 'parallel "convert {} -set colorspace sRGB -colorspace RGB -filter Robidoux -resize 200x200 -colorspace sRGB -quality 90 ../bench_out/{.}_magick_200x200.jpg" ::: *.jpg' @@ -35,10 +35,10 @@ if [[ "$1" == "thumbnail" ]]; then fi if [[ "$1" == "downscale" ]]; then # shellcheck disable=SC2016 - hyperfine --export-markdown results.md \ - 'parallel "$HOME/bin/imageflow_tool v0.1/ir4 --in {} --out ../bench_out/{.}_2000x2000.jpg --command width=\"2000&height=2000&mode=max&quality=90&jpeg.turbo=true\"" ::: *.jpg' \ + hyperfine --export-markdown results.md --warmup 1 \ + 'parallel "$HOME/bin/imageflow_tool v0.1/ir4 --in {} --out ../bench_out/{.}_2000x2000.jpg --command width=2000&height=2000&quality=90" ::: *.jpg' \ 'parallel "vipsthumbnail --linear --size=2000x2000 --output=../bench_out/{.}_vips_2000x2000.jpg[Q=90] {}" ::: *.jpg' \ - 'parallel "gm convert {} -set colorspace sRGB -colorspace RGB -filter Mitchell -resize 2000x2000 -colorspace sRGB -quality 90 ../bench_out/{.}_gm_0200x0200.jpg" ::: *.jpg' \ + 'parallel "gm convert {} -set colorspace sRGB -colorspace RGB -filter Mitchell -resize 2000x2000 -colorspace sRGB -quality 90 ../bench_out/{.}_gm_2000x2000.jpg" ::: *.jpg' \ 'parallel "convert {} -set colorspace sRGB -colorspace RGB -filter Robidoux -resize 2000x2000 -colorspace sRGB -quality 90 ../bench_out/{.}_magick_2000x2000.jpg" ::: *.jpg' echo "=============== Results in Markdown format ======================" diff --git a/imageflow_tool/src/cmd_build.rs b/imageflow_tool/src/cmd_build.rs index 341dfbb2c..20bf9809a 100644 --- a/imageflow_tool/src/cmd_build.rs +++ b/imageflow_tool/src/cmd_build.rs @@ -398,14 +398,16 @@ impl CmdBuild { } /// /// Write the JSON response (if present) to the given file or STDOUT - pub fn write_response_maybe(&self, response_file: Option<&str>) -> std::io::Result<()> { + pub fn write_response_maybe(&self, response_file: Option<&str>, allow_stdout: bool) -> std::io::Result<()> { if self.response.is_some() { if let Some(filename) = response_file { let mut file = BufWriter::new(File::create(filename).unwrap()); file.write_all(&self.get_json_response().response_json)?; } else { - std::io::stdout().write_all(&self.get_json_response().response_json)?; + if allow_stdout { + std::io::stdout().write_all(&self.get_json_response().response_json)?; + } } } diff --git a/imageflow_tool/src/lib.rs b/imageflow_tool/src/lib.rs index 13372870c..e0adde1e3 100644 --- a/imageflow_tool/src/lib.rs +++ b/imageflow_tool/src/lib.rs @@ -87,6 +87,7 @@ pub fn main_with_exit_code() -> i32 { .help("Replace/add outputs for the operation file")) //.arg(Arg::with_name("demo").long("demo").takes_value(true).possible_values(&["example:200x200_png"])) .arg(Arg::with_name("json").long("json").takes_value(true).required(true).help("The JSON operation file.")) + .arg(Arg::with_name("quiet").long("quiet").takes_value(false).help("Don't write the JSON response to stdout")) .arg(Arg::with_name("response").long("response").takes_value(true).help("Write the JSON job result to file instead of stdout")) .arg(Arg::with_name("bundle-to").long("bundle-to").takes_value(true).help("Copies the recipe and all dependencies into the given folder, simplifying it.")) .arg(Arg::with_name("debug-package").long("debug-package").takes_value(true).help("Creates a debug package in the given folder so others can reproduce the behavior you are seeing")) @@ -101,6 +102,7 @@ pub fn main_with_exit_code() -> i32 { ) .arg(Arg::with_name("out").long("out").multiple(true).min_values(1).required(true) .help("Output image")) + .arg(Arg::with_name("quiet").long("quiet").takes_value(false).help("Don't write the JSON response to stdout")) .arg(Arg::with_name("response").long("response").takes_value(true).help("Write the JSON job result to file instead of stdout")) .arg(Arg::with_name("command").long("command").takes_value(true).required(true).help("w=200&h=200&mode=crop&format=png&rotate=90&flip=v - ImageResizer4 style command")) .arg(Arg::with_name("bundle-to").long("bundle-to").takes_value(true).help("Copies the recipe and all dependencies into the given folder, simplifying it.")) @@ -161,7 +163,7 @@ pub fn main_with_exit_code() -> i32 { let dir = Path::new(&dir); return builder.bundle_to(dir); } else { - builder.write_response_maybe(m.value_of("response")) + builder.write_response_maybe(m.value_of("response"), !m.is_present("quiet")) .expect("IO error writing JSON output file. Does the directory exist?"); builder.write_errors_maybe().expect("Writing to stderr failed!"); return builder.get_exit_code().unwrap(); diff --git a/imageflow_tool/src/self_test.rs b/imageflow_tool/src/self_test.rs index 74419ac1e..5106977e6 100644 --- a/imageflow_tool/src/self_test.rs +++ b/imageflow_tool/src/self_test.rs @@ -415,6 +415,17 @@ pub fn run(tool_location: Option) -> i32 { _ => panic!("Build result not sent"), } + } + { + let c = c.subfolder_context("queryquiet"); + c.create_blank_image_here("100x100", 100, 100, s::EncoderPreset::libjpeg_turbo()); + + let result = + c.exec("v0.1/ir4 --quiet --command \"width=60&height=40&mode=max&format=jpg\" --in 100x100.jpg --out out4.jpg"); + + result.expect_status_code(Some(0)); + assert_eq!(0, result.stdout_byte_count()); + } { let c = c.subfolder_context("gif");