Glimpse

Scripting

stdin, stdout, JSON output, and clean pipes.

On this page 3

The image commands read stdin and write stdout, so you can use glimpse inside shell pipelines.

Pipes

The transform commands and info read - as "the image comes from stdin". --output=- (short form -o-) writes the raw image bytes to stdout:

bash
cpx glimpse thumbnail photo.jpg --output=- | imgcat
cat photo.png | cpx glimpse convert - --format=webp -o photo.webp
cpx glimpse convert photo.png --format=avif --json | jq .size

When the image bytes go to stdout (--output=-), the human summary, or the --json line, moves to STDERR. The pipe carries only the image. When the output is a file, the summary or the JSON prints to stdout as usual, which is what makes the jq example above work.

JSON output

Every image command accepts --json:

  • The transforms (convert, optimize, resize, thumbnail) print the result metadata: format, MIME type, size, and dimensions.
  • info prints the raw metadata object.
  • analyze prints the estimates; on a directory scan, one entry per file.
  • check prints the report, including the files that need optimization and the ones that could not be checked.
  • usage prints the raw usage summary.

Exit codes

  • 0: the command did what you asked.
  • 1: it did not. For check, that includes "an image is over the threshold" and "a file could not be checked"; for init, a requested baseline seed that failed.

cpx glimpse init and the auth commands are interactive by design and do not read image bytes from stdin. In scripts, prefer their flags (--update-baseline, --workflow, --workflow-mode=check, --token=, --no-interaction) over piped answers.