CLI Reference
Automate batch image compression and format conversion with the imgcompress CLI. Process thousands of images from terminal scripts or CI/CD pipelines — runs entirely on your self-hosted server with no cloud dependency.
Automate batch image compression and format conversion with the imgcompress CLI. Process thousands of images from terminal scripts or CI/CD pipelines — runs entirely on your self-hosted server with no cloud dependency.
The CLI is for automation and batch processing. If you're converting thousands of images or building a script, it's faster and more flexible than the web UI.
Start with the Web UI. Come back here when you want to automate.
The CLI runs inside the Docker container. To access your local files, you mount your folder using the -v flag:
$(pwd): your current local folder/container/images: where the container reads input files/container/done: where the container writes output filesBefore running any of the examples below, refresh your local image so you're not running an old version:
bashdocker pull karimz1/imgcompress:latest
bashdocker run --rm \ -v "$(pwd):/container/images" \ -v "$(pwd)/done:/container/done" \ karimz1/imgcompress:latest \ cli \ /container/images/photo.jpg \ /container/done \ --quality 80 \ --format png
bashdocker run --rm \ -v "$(pwd):/container/images" \ -v "$(pwd)/done:/container/done" \ karimz1/imgcompress:latest \ cli \ /container/images \ /container/done \ --format jpeg \ --quality 85
bashdocker run --rm \ -v "$(pwd):/container/images" \ -v "$(pwd)/done:/container/done" \ karimz1/imgcompress:latest \ cli \ /container/images \ /container/done \ --format png \ --remove-background
| Flag | Description |
|---|---|
--quality | Compression quality, 1-100. Higher = better quality, larger file. |
--width | Resize to this width in pixels. Aspect ratio is preserved. |
--format | Output format: jpeg, png, webp, avif. |
--remove-background | Use local AI to remove the image background. |
--json-output | Output structured JSON, useful for piping results into other programs or scripts. |
Add --json-output at the end of any command to get results that other programs can read easily. Instead of plain text, imgcompress returns a structured JSON response with paths, sizes, and status for every file. Perfect for shell pipelines, CI jobs, or any tool that consumes JSON.
bashdocker run --rm \ -v "$(pwd):/container/images" \ -v "$(pwd)/done:/container/done" \ karimz1/imgcompress:latest \ cli \ /container/images \ /container/done \ --format webp \ --quality 85 \ --json-output