Skip to content

Core concepts

Once you understand these five concepts, every flag in imgsqz makes sense.

Terminal window
imgsqz <input...> [options]
  • <input...> — one or more image paths (globs are expanded by your shell). This is the only required argument.
  • [options] — flags that control format, quality, size, naming and safety.

Everything else is a variation on this shape.

Run imgsqz with just an input and you get a deliberate set of defaults:

DefaultValueWhy
FormatjpgUniversally supported, great with mozjpeg
Quality80A strong size/quality sweet spot
Output<name>_<timestamp>.jpg next to sourceNever overwrites your original
MetadatastrippedSmaller files; privacy by default
Orientationauto-correctedPhone photos come out upright
ResizenoneKeeps original dimensions

So imgsqz photo.png means “make a stripped, upright, quality-80 JPG copy and don’t touch my original.”

By default the output filename is derived from the input:

photo.png → photo_20260611_132517.jpg
└─ YYYYMMDD_HHMMSS at the moment you ran it

The timestamp guarantees runs don’t collide and your source is safe. You can change this behavior:

  • --no-timestamp drops the suffix → photo.jpg
  • -o, --output <path> sets an exact path (single input only)
  • --replace overwrites the source in place (see safety below)

4. Safety: your source is never clobbered by accident

Section titled “4. Safety: your source is never clobbered by accident”

imgsqz goes out of its way not to destroy originals:

  • The default timestamped name can’t collide with the source.
  • If a computed output path would equal the input and you didn’t pass --replace, imgsqz refuses and tells you to use --replace or -o.
  • --replace itself is atomic: it writes to a temporary file (name.imgsqz.tmp) and then renames it over the original. An interrupted run leaves your source intact.

For each input, imgsqz builds a sharp pipeline in a fixed order:

read ─▶ auto-rotate (EXIF) ─▶ resize? ─▶ grayscale? ─▶ keep metadata? ─▶ encode ─▶ write

Knowing this order explains the interactions:

  • Rotate happens first, so --width/--height apply to the upright image.
  • Resize honors orientation, so “width” always means visual width.
  • Encoding is last, so format-specific flags (--lossless, --quality) apply to the final pixels.

That’s the whole mental model. Next: Compressing images.