Skip to content

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.

Set just one dimension and the other scales to preserve the aspect ratio:

Terminal window
# 800px wide, height auto
imgsqz photo.jpg --width 800
# 600px tall, width auto
imgsqz photo.jpg --height 600

Both flags require a positive integer (pixels).

Set --width and --height together and the --fit mode decides how the image fills that box.

Terminal window
imgsqz photo.jpg --width 400 --height 400 --fit cover

--fit accepts five modes (default inside). They only matter when both width and height are set.

ModeBehaviorAspect ratioMay crop?
inside (default)Shrinks to fit within the boxPreservedNo
outsideGrows to cover the box, then you can crop laterPreservedNo
coverFills the box exactly, cropping overflowPreservedYes
containFits within the box, padding the restPreservedNo (adds padding)
fillStretches to the exact boxNot preservedNo
  • Thumbnails / avatarscover (fills a square, crops edges).
  • “Make it no bigger than N×N”inside (the default).
  • Exact canvas with letterboxingcontain.
  • Don’t care about distortionfill.
Terminal window
# Square avatar, cropping to fill
imgsqz 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 needed
imgsqz still.png --width 1280 --height 720 --fit contain

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:

Terminal window
# Will NOT upscale a small source (stays at native size)
imgsqz small.jpg --width 4000
# Explicitly allow upscaling
imgsqz small.jpg --width 4000 --enlarge

All of these compose. A common web-prep command:

Terminal window
imgsqz hero.png -f avif -q 50 --width 1600

That reads hero.png, auto-rotates, caps the width at 1600px (no enlargement), and writes a quality-50 AVIF.


Next: Batch processing.