CLI Reference
Batch-convert, compress, upscale and crop images from scripts or CI with the imgcompress CLI. Every flag explained, runs inside your Docker container.
Get StartedAutomation
Batch-convert, compress, upscale and crop images from scripts or CI with the imgcompress CLI. Every flag explained, runs inside your Docker container.
Use the CLI to convert many images at once or from a script or CI job. It runs inside the same Docker image as the web app. New to imgcompress? Start with the Web UI.
Prerequisites: Docker. Pull the newest image first: docker pull karimz1/imgcompress:latest.
Mount your folder into the container and tell the CLI where to read and write:
bashdocker run --rm \ -v "$(pwd):/container/images" \ -v "$(pwd)/done:/container/done" \ karimz1/imgcompress:latest \ cli /container/images /container/done \ --format webp --quality 85
$(pwd): your current folder./container/images: where the CLI reads. Use a file path for one image, or the folder for all of them./container/done: where the results go.Use the command above and change the flags at the end.
| Task | Flags |
|---|---|
| One image to PNG | Input /container/images/photo.jpg, then --format png --quality 80 |
| A folder to JPEG | --format jpeg --quality 85 |
| Remove backgrounds | --format png --remove-background |
| Upscale with AI | --format png --upscale 4x --upscale-model anime |
| Crop to an exact size | --format webp --fit 1280x640 --fit-mode blur |
| Lossless WebP | --format webp --webp-lossless |
| Flag | Description |
|---|---|
--format | Output format: jpeg (default), png, webp, avif or pdf. |
--quality | Quality for JPEG, AVIF and WebP, 1-100 (default 85). Higher = better quality, larger file. |
--width | Resize to this width in pixels. The aspect ratio stays the same. |
--webp-lossless | Lossless WebP. --quality is then ignored. |
--remove-background | Remove the background with the built-in AI. Works with png, webp and avif. |
--upscale | Make images bigger with AI: 2x, 4x, 8x, 1080p, 4k, 6k, 8k or 16k. Replaces --width. Not for PDF. AI upscaling |
--upscale-model | general (default), general-denoise-medium, general-denoise-low or anime. |
--fit | Output exactly this size, e.g. 1280x640. Replaces --width. With --upscale, the image is upscaled first. Smart crop |
--fit-mode | How --fit handles a different shape: crop (default), blur, solid or transparent. |
--fit-color | Fill color for --fit-mode solid, e.g. #ffffff (default). |
--fit-anchor | What to keep when cropping: auto (default, finds the important part), center, top, bottom, left or right. |
--pdf-preset | PDF page size: original (default), a4-auto, a4-portrait, a4-landscape, letter-auto, letter-portrait, letter-landscape, mobile-portrait, mobile-landscape. |
--pdf-scale | For PDF presets: fit (default, letterbox) or fill (crop). |
--pdf-margin-mm | PDF margin in millimeters for presets (default 10). |
--pdf-paginate | Split long images across several PDF pages (presets only). |
--json-output | Output structured JSON, useful for piping results into other programs or scripts. |
--debug | More detailed logs. |
Add --json-output to get a JSON result with paths, sizes and status for every file instead of plain text. Handy for shell pipelines and CI.
bashdocker run --rm \ -v "$(pwd):/container/images" \ -v "$(pwd)/done:/container/done" \ karimz1/imgcompress:latest \ cli /container/images /container/done --format webp --json-output