How to use this calculator
Preserve an image’s proportions while fitting it inside a target frame, with the remaining margins shown.
- Enter Source image width (px), Source image height (px), Target frame width (px), Target frame height (px). Match the units shown beside each field and review the result together with the assumptions below.
- Read the worked example below to check the expected input format and result.
- Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
How this calculation works
When an image must fit a fixed canvas without being cropped, the scale is limited by whichever target dimension is reached first. This calculator uses a contain fit: it enlarges or reduces the source uniformly until it fits inside both frame dimensions, then reports the remaining horizontal and vertical margins.
Inputs and units
sourceWidth— Source image width (px)- Enter the image’s active pixel width.
sourceHeight— Source image height (px)- Enter the image’s active pixel height.
frameWidth— Target frame width (px)- Enter the available canvas width in the same unit.
frameHeight— Target frame height (px)- Enter the available canvas height in the same unit.
Formula
Source ratio = source width ÷ source height. Fit scale s = min(target width ÷ source width, target height ÷ source height). Fitted width = source width × s; fitted height = source height × s; centered margin per side = (target dimension − fitted dimension) ÷ 2.
Method
Enter source image width and height plus the target frame width and height, all in the same unit (pixels are common). The tool preserves the source aspect ratio and centers the fitted image in the frame; nonzero margins indicate letterboxing or pillarboxing.
Worked example
A 4,000 × 3,000 image fitted inside a 1,920 × 1,080 frame has a 4:3 source ratio. Height is limiting, so the scale is 1,080 ÷ 3,000 = 0.36 and the image becomes 1,440 × 1,080 px, leaving 240 px on each horizontal side.
Assumptions and limits
This is a contain fit that keeps the entire image visible. It does not crop to fill the frame, add pixels, resample an image, choose an export format, or account for interface safe areas. Fractional fitted dimensions are mathematical values and may need rounding for a pixel grid.
Frequently asked questions
Will this crop my image to fill the frame?
No. It uses a contain fit, so the full source remains visible and margins may remain on two sides.
How do I fill the frame without margins?
That usually requires cropping. Use a crop or cover workflow and choose which part of the source should be removed.
Do the dimensions have to be pixels?
No. Any consistent unit works, but source and target width and height must all use that same unit.
Why are fitted dimensions sometimes fractional?
The exact proportional scale can land between pixel boundaries. Choose a rounding policy when exporting to an integer pixel grid.
How do I use the Image Aspect Ratio and Fit Calculator?
Enter Source image width (px), Source image height (px), Target frame width (px), Target frame height (px). Match the units shown beside each field and review the result together with the assumptions below.
Read our calculation methodology.