Skip to content

Output paths & naming

imgsqz gives you four ways to decide where output lands. Pick based on whether you’re processing one file or many.

With no naming flags, the output goes beside the input with a _<timestamp>.<ext> suffix:

Terminal window
imgsqz photo.png
# photo.png → photo_20260611_132517.jpg

The timestamp is YYYYMMDD_HHMMSS captured when the run starts. It guarantees a fresh name every run and means your source is never overwritten.

Drop the suffix to get name.<ext> next to the source:

Terminal window
imgsqz photo.png --no-timestamp
# photo.png → photo.jpg

Name the output file precisely. The extension you give is just a name — the actual encoding is set by -f:

Terminal window
imgsqz photo.jpg -o build/thumb.webp -f webp -q 70

imgsqz creates missing directories in the path automatically, so this works even if build/ doesn’t exist yet:

Terminal window
imgsqz photo.jpg -o dist/img/hero.avif -f avif -q 50

Write the result back over the original file:

Terminal window
imgsqz photo.jpg --replace -q 80

This is the one case where the input is the output. It’s done atomically — imgsqz writes photo.jpg.imgsqz.tmp first, then renames it over photo.jpg — so an interrupted run can’t corrupt your file. See Replacing files in place for the full story.

The output extension follows the format, not the input:

CommandOutput name
imgsqz a.pnga_<ts>.jpg (default format)
imgsqz a.png -f webpa_<ts>.webp
imgsqz a.png -f webp --no-timestampa.webp
imgsqz a.png -o out/b.avif -f avifout/b.avif
imgsqz a.png -f png --replacea.png (in place)

If your flags would make the output path equal the input path and you did not pass --replace, imgsqz stops with:

Refusing to overwrite the input file. Use --replace if that's what you want,
or specify -o/--output.

This is a safety net — for example, imgsqz photo.jpg --no-timestamp (which would compute photo.jpg) is blocked unless you add --replace.


Next: Metadata & orientation.