The aspect ratio of a rectangle is an ordered relationship between its width and height. If two rectangles have widths W1 and W2 and heights H1 and H2, they have the same aspect ratio when W1 / H1 = W2 / H2. For positive dimensions, this equality can be rewritten as W1 × H2 = W2 × H1.
The cross-product form is particularly useful because it avoids inaccuracies caused by rounding repeating decimals. Integer pixel dimensions provide a natural connection to number theory. The ratio 3000:2000 can be reduced to 3:2 by dividing both dimensions by 1000.
More generally, the greatest common divisor gives the largest integer factor shared by both dimensions. Dividing through by that factor produces a ratio whose two terms have no further common integer divisor greater than one. This simplification does not discard information about shape, but it intentionally discards information about absolute scale.
Both a 300 by 200 image and a 6000 by 4000 image reduce to 3:2. The second image contains substantially more pixels despite sharing the same geometric proportions. For proportional transformations, the concept of similar rectangles is central.
Multiplying both dimensions by a positive scale factor preserves the ratio exactly in continuous mathematics. By contrast, applying different factors horizontally and vertically changes the ratio and generally distorts visible geometry. A circle, for example, becomes an ellipse under nonuniform scaling.
Fitting introduces another layer of reasoning. A source rectangle may need to occupy a destination region with a different aspect ratio. Contain scaling chooses the smaller dimension-based scale factor, guaranteeing that neither scaled dimension exceeds the destination. Cover scaling chooses the larger factor, guaranteeing that neither scaled dimension falls short.
The first may introduce empty space; the second may require cropping. Several edge cases deserve attention. A zero height invalidates division, while zero width does not describe a conventional image rectangle.
Negative dimensions are outside ordinary image-sizing assumptions. Noninteger calculated dimensions may require rounding for raster output. In addition, aspect ratios derived solely from pixel counts assume that horizontal and vertical pixels represent equal physical lengths. Images with non-square pixel-aspect-ratio metadata require additional interpretation when describing displayed geometry.