Aspect Ratio Calculator

About this calculator

Enter the source and canvas sizes in pixels. Compare how much space Fit leaves around the whole image and how much Fill crops away. See the exact geometry and a separate whole-pixel plan.

Calculator inputs

Example: source 4000 x 3000, canvas 1920 x 1080.

Edit the example to use your dimensions.

Controls are loading. Without JavaScript they remain disabled; manual examples and formulas below remain readable.

Square-pixel dimension planning
Source dimensions

Swap needs two valid dimensions. Width and height stay ordered.

Target canvas

Swap needs two valid canvas dimensions. Fit keeps the whole image; Fill removes edges.

Syntax and planning limits

Dimensions are positive integers from 1 to 1000000 pixels: one to seven ASCII digits after outer ASCII whitespace, at most 32 raw characters. No signs, decimals, commas, exponents, units or expressions. Leading zeros normalize; empty is not zero.

Fit floors exact dimensions; Fill ceils them. Resize rounds only the other axis; nearest half-way ties upward. Odd padding/crop goes to right/bottom. These are product conventions, not mandated by CSS or every editor. An exact fraction may be valid while no usable whole-pixel output exists.

Embed this calculator

Paste this code into a Custom HTML block on your site. The calculator fits the width of the block. Adjust the height in the code if you want more room for results.

Find this widget in the publisher directory

What choice does Fit versus Fill answer?

Fit retains the complete source rectangle inside the canvas. Empty space becomes padding. Fill covers the canvas with the preserved-ratio source rectangle; edges outside the canvas are omitted. Both exact geometries preserve proportions. Our separate integer plan can change proportions when a fractional dimension is rounded. No pixels from your actual image are read or changed.

For a 4000 by 3000 source in a 1920 by 1080 canvas, Fit uses scale 9/25: 1440 by 1080, with 240 pixels on each side. Exactly 25% of the canvas is empty. Fill uses scale 12/25: 1920 by 1440, cropping 180 scaled pixels from top and bottom. Its exact source crop begins at (0,375), with width 4000 and height 2250. Exactly 25% of the original source area is omitted. Those percentages happen to agree, but one denominator is canvas area and the other is original source area.

Why separate exact geometry from whole pixels?

A 3 by 2 source in a 5 by 5 canvas has exact Fit size 5 by 10/3. Our practical Fit floors each dimension to 5 by 3, with one padding pixel above and below. Exact Fill is 15/2 by 5; the whole-pixel resample is 8 by 5, with one crop pixel on the left and two on the right. Odd leftover pixels go to the right or bottom by our stated convention. The rounded sizes have their own aspect errors; neither should be called an exact undistorted version of the fractional geometry.

Fit uses the smaller target-to-source axis scale. Fill uses the larger. Exact centered source crop is calculated by dividing the canvas dimensions by the Fill scale, then taking half the remaining source span as the origin. Coordinates are distances from source edges, not inclusive pixel-index endpoints. Rounded resample crop does not replace those exact source coordinates. Where whole-pixel area percentages are listed, they use their separately named canvas or resampled-image denominator.

How does resizing and its signed error work?

Choose one target axis. Resizing 1920 by 1080 to width 640 gives exactly 640 by 360. With width X, the other dimension is X times source height divided by source width; the height-anchor formula is the reverse. Only the other axis is rounded. Nearest half-way ties round upward; Down and Up are explicit alternatives.

Resizing a 2 by 3 source to width 1 gives exact height 3/2. Nearest produces 1 by 2, which is 25% narrower in aspect ratio; Down produces 1 by 1, which is 50% wider. Signed error compares the actual output width/height ratio against the source width/height ratio. It is not an image-quality score. Increasing numerical dimensions cannot restore missing detail.

What if no usable pixel size exists?

Positive exact geometry can have an axis below one pixel or above this tool's 1000000-pixel output bound. A 1000000 by 1 source fitted into 1 by 1 has exact height 1/1000000; flooring it would give zero. The geometry remains valid and useful, while planned-dimensions copy is disabled. Full explanation, print and numeric sharing remain available. No fabricated 1 by 0 export or silent clamp is supplied.

For Resize, a separate exact-ratio alternative uses integer multiples of the reduced source ratio. The largest multiple must satisfy the requested anchor bound and both output-axis bounds. A 1 by 1000000 source requested at width 1000000 has exact height 1000000000000, so its requested pixel plan is unavailable. The bounded exact alternative is only 1 by 1000000. It is a different, much smaller result, never silently substituted and never used to enable copying an unavailable requested size.

What does Find ratio add to this workflow?

Width and height remain ordered. A 1080 by 1920 portrait is 9:16; 1919 by 1080 remains 1919:1080 instead of being snapped to 16:9. Divide both positive integers by their greatest common divisor. General proportion solving and basic scaling already exist in the Ratio Calculator; this page's distinct task is the complete Fit/Fill and pixel-plan decision.

Literal ratio examples replace dimensions only after an explicit Apply action. They are not platform sizes or your image measurements. The fixed CSS helper sets a preferred box ratio; at least one CSS dimension needs automatic sizing. It neither modifies a file nor overrides two fixed dimensions.

Inputs, privacy and model limits

Enter one to seven ASCII digits, dimension 1 through 1000000, with at most 32 raw characters including outer ASCII whitespace. Signs, commas, decimals, exponents, units and expressions are rejected. Local leading zeros normalize; public numeric inputs are canonical. Square pixels and centered geometry are assumed. No EXIF, physical screen size, PPI, codec multiples, platform-size catalogue, non-square pixels, image resampling or image-quality promise is included.

Each mode keeps unsaved drafts in page memory only. Mathematical edits invalidate results; choosing between already-computed Fit and Fill keeps geometry current but revokes earlier export consent. Public links require explicit consent and contain active dimensions, selected policy and rounding only. Anyone with the link can read them. No account, autosave, source URL, file path, image upload or input telemetry is added.

Method and review

The W3C CSS Images Level 3 contain and cover definitions inform the exact rectangle constraints. The retrieved published document was the December 18, 2023 Candidate Recommendation Draft, not a final Recommendation. MDN object-fit explains the practical distinction. Our centering, integer floor/ceil, ties-up and odd-right/bottom policies are derived product conventions, not rules mandated by CSS or every editor. This is not a browser layout or file-processing engine.

Method reviewed November 8, 2026 using independent rational fixtures and bounded alternative maximality checks. That date describes actual method work, not image-processing certification or imaging credentials. Competitors already offer substantial overlapping planners. Useful geometry and correct markup do not prove indexing, rankings or future traffic.

Frequently asked questions

Does this resize or crop an image file?
No. It computes a dimension and crop/padding plan from typed numbers. No file is uploaded, processed or downloaded.
Does whole-pixel rounding always preserve the exact ratio?
No. The exact geometry preserves proportions, while the separately stated integer convention can change them. The result shows signed aspect error.
Why can a valid result have no copyable pixel size?
Its exact geometry can round below one pixel or exceed an output-axis bound. Full geometry remains useful, while requested-size copy is disabled.

Formulas and sample results on this page were checked against independent references. Page last reviewed or updated . How we verify calculators. Project led by Shaun Connell.