Resizing & fit modes
imgsqz can resize as part of the same pass that compresses and converts. Resize happens after EXIF auto-rotation, so width and height always refer to the visually upright image.
Resize by width or height
Section titled “Resize by width or height”Set just one dimension and the other scales to preserve the aspect ratio:
# 800px wide, height autoimgsqz photo.jpg --width 800
# 600px tall, width autoimgsqz photo.jpg --height 600Both flags require a positive integer (pixels).
Resize by both dimensions
Section titled “Resize by both dimensions”Set --width and --height together and the --fit mode decides how the image
fills that box.
imgsqz photo.jpg --width 400 --height 400 --fit coverFit modes
Section titled “Fit modes”--fit accepts five modes (default inside). They only matter when both
width and height are set.
| Mode | Behavior | Aspect ratio | May crop? |
|---|---|---|---|
inside (default) | Shrinks to fit within the box | Preserved | No |
outside | Grows to cover the box, then you can crop later | Preserved | No |
cover | Fills the box exactly, cropping overflow | Preserved | Yes |
contain | Fits within the box, padding the rest | Preserved | No (adds padding) |
fill | Stretches to the exact box | Not preserved | No |
Picking a fit mode
Section titled “Picking a fit mode”- Thumbnails / avatars →
cover(fills a square, crops edges). - “Make it no bigger than N×N” →
inside(the default). - Exact canvas with letterboxing →
contain. - Don’t care about distortion →
fill.
# Square avatar, cropping to fillimgsqz avatar.jpg --width 256 --height 256 --fit cover -f webp
# Cap dimensions without cropping (fits inside 1200×1200)imgsqz photo.jpg --width 1200 --height 1200 --fit inside
# Exact 16:9 canvas, padded if neededimgsqz still.png --width 1280 --height 720 --fit containUpscaling
Section titled “Upscaling”By default imgsqz never enlarges an image beyond its source dimensions —
asking for --width 4000 on a 1000px-wide source leaves it at 1000px. This
avoids blurry upscaled output.
Pass --enlarge to allow upscaling:
# Will NOT upscale a small source (stays at native size)imgsqz small.jpg --width 4000
# Explicitly allow upscalingimgsqz small.jpg --width 4000 --enlargeResize + convert + compress in one shot
Section titled “Resize + convert + compress in one shot”All of these compose. A common web-prep command:
imgsqz hero.png -f avif -q 50 --width 1600That reads hero.png, auto-rotates, caps the width at 1600px (no enlargement),
and writes a quality-50 AVIF.
Next: Batch processing.