Skip to content

Commit

Permalink
Add --quiet command to imageflow_tool to supress STDOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
lilith committed Apr 23, 2020
1 parent 6416550 commit b6fec50
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
10 changes: 5 additions & 5 deletions docker/imageflow_bench_ubuntu20/bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 ======================"
Expand Down
6 changes: 4 additions & 2 deletions imageflow_tool/src/cmd_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
}

}
Expand Down
4 changes: 3 additions & 1 deletion imageflow_tool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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."))
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions imageflow_tool/src/self_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,17 @@ pub fn run(tool_location: Option<PathBuf>) -> 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");
Expand Down

2 comments on commit b6fec50

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • esults
  • graphicsmagick
  • jpegsize
  • queryquiet
To accept these changes, run the following commands
remove_obsolete_words=$(mktemp)
echo '#!/usr/bin/perl -ni
my $re=join "|", qw('"
jsoref
megapixels
"');
next if /^($re)(?:$| .*)/;
print;' > $remove_obsolete_words
chmod +x $remove_obsolete_words
for file in .github/actions/spell-check/whitelist/42f15d0ed3748dd6a1b8c1f026d297f0625fb5eb.txt .github/actions/spell-check/whitelist/whitelist.txt; do $remove_obsolete_words $file; done
rm $remove_obsolete_words
(
echo "
esults
graphicsmagick
jpegsize
queryquiet
"
) | sort -u -f | perl -ne 'next unless /./; print' > new_whitelist.txt && mv new_whitelist.txt '.github/actions/spell-check/whitelist/b6fec504c7c2d13be4e010c8774734289dd3488b.txt'

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New misspellings found, please review:

  • esults
  • graphicsmagick
  • jpegsize
  • queryquiet
To accept these changes, run the following commands
remove_obsolete_words=$(mktemp)
echo '#!/usr/bin/perl -ni
my $re=join "|", qw('"
jsoref
megapixels
"');
next if /^($re)(?:$| .*)/;
print;' > $remove_obsolete_words
chmod +x $remove_obsolete_words
for file in .github/actions/spell-check/whitelist/42f15d0ed3748dd6a1b8c1f026d297f0625fb5eb.txt .github/actions/spell-check/whitelist/whitelist.txt; do $remove_obsolete_words $file; done
rm $remove_obsolete_words
(
echo "
esults
graphicsmagick
jpegsize
queryquiet
"
) | sort -u -f | perl -ne 'next unless /./; print' > new_whitelist.txt && mv new_whitelist.txt '.github/actions/spell-check/whitelist/b6fec504c7c2d13be4e010c8774734289dd3488b.txt'

Please sign in to comment.