Skip to main content
Geometry is a string format that specifies dimensions, offsets, and resize behavior. It appears in -resize, -crop, -extent, -thumbnail, -scale, -sample, and other options that manipulate image dimensions. The authoritative overview is Command-line processing (geometry) on imagemagick.org; this page summarizes the parts doc readers use most often.

Base syntax

Unless noted, examples assume a 1600×1200 source (4∶3 aspect ratio). For “fit inside” sizes, ImageMagick uses scale = min(W/w, H/h) so neither output dimension exceeds the box.
Geometry dimensions are in pixels. ImageMagick does not factor in DPI or print resolution when interpreting geometry strings. An image at 300 DPI and an image at 72 DPI with the same pixel dimensions receive the same resize result.

Resize modifier flags

Modifier flags are appended to the end of a geometry string. They change how ImageMagick handles aspect ratio and sizing constraints.

Independent percentages on both axes (W%xH%)

Strings like 50%x25% scale width and height by different percentages, so the aspect ratio changes (unlike a single 50%, which scales both axes together). See the W%xH% row in the base syntax table. That trips people who expect 50%x25% to mean “50% overall.” All examples below use a 1600x1200 input image and a target of 800x400.

No flag (default)

Fits the image within 800x400 while preserving aspect ratio. The result never exceeds either dimension. Output: 533x400 (height is the limiting dimension).

! Force exact dimensions

Ignores aspect ratio and forces the image to exactly 800x400. Output: 800x400.
The ! flag distorts the image if the target aspect ratio differs from the source. A 4:3 image forced into 2:1 dimensions will appear horizontally stretched.

> Only shrink

Resizes the image only if it is larger than the target. If the image already fits within the dimensions, it stays unchanged.

< Only enlarge

Resizes the image only if it is smaller than the target. Larger images stay unchanged.

^ Fill area

^ means “cover” the box, not “fit inside.” ImageMagick scales until both dimensions are at least the target (max(W/w, H/h)). For 1600×1200 into an 800×400 box, the width hits 800 first, producing 800×600. The image is 150px taller than the 400px target. That overflow is expected; you still need a crop or extent step if the deliverable must be exactly 800×400. This is typically paired with -gravity center -extent (or -crop) to trim the extra:
Final output: 800×400 (scaled to cover, then canvas cropped from the center).

Offset syntax

Offsets specify a position within the image, written as +X+Y or -X-Y after the dimensions. They are primarily used with -crop and -extent.
This extracts a 400x300 region starting 100 pixels from the left edge and 50 pixels from the top edge. The +repage resets the virtual canvas to match the cropped dimensions. Negative offsets shift in the opposite direction:
This shifts the crop region 50 pixels left and 25 pixels up from the default origin. Pixels outside the image boundary are not included; the result may be smaller than 400x300.

Gravity and crop offsets

When -gravity is set, crop offsets are measured from the gravity anchor point instead of the top-left corner. Offsets add to the anchor in the direction ImageMagick defines for that gravity (see the official geometry page for edge cases). -gravity persists for all subsequent spatial operations until explicitly reset. To reset it:
The first crop uses Center gravity. The second crop uses the default top-left origin after -gravity None resets it.

Options that accept geometry

Resize operations (all preserve aspect ratio by default, all accept modifier flags): Crop and extent operations (use WxH+X+Y offset syntax):

Edge cases

x600 vs 0x600

These are different. x600 omits the width, so ImageMagick calculates it proportionally from the height. 0x600 specifies a width of zero, which produces a 1x1 pixel output. Always omit the dimension rather than setting it to zero.

Two-axis percentages (50%x25%)

Covered in the base table above: width and height scale independently, so the picture stretches unless both percentages match.

Decimal percentages

Values like 33.3% are valid. ImageMagick rounds the result to the nearest whole pixel. A 1600x1200 image at 33.3% becomes 533x400.

Area resize (@)

The @ flag targets an approximate pixel count rather than specific dimensions. 640000@ on a 1600x1200 image produces 924x693 (area = 640,332). The result preserves aspect ratio and gets as close to the target area as possible.

Shell escaping

The >, <, ^, and ! characters have special meaning in most shells. Wrap geometry strings in single quotes on Linux/macOS ('800x600>') or double quotes on Windows ("800x600>"). The backslash escape (800x600\>) also works on Linux/macOS.

See also

  • Common options reference for -strip, -quality, -gravity, -background, -composite, and related flags used together with geometry in real commands.