Image resize, crop and padding dimensions
Calculate image placement in a frame and crop bounds in continuous pixel coordinates
Results
—px
—px
- Display-coordinate scale
- —×
- Horizontal pixel scale after orientation
- —×
- Vertical pixel scale after orientation
- —×
Results update automatically when the required values are entered.
Method, applicability and sources
Calculation method
Apply EXIF orientation, then calculate display dimensions using the oriented pixel width/height ratio. For contain, s=min(frame width÷display width, frame height÷display height); for cover, s=max(the same two values). A specified ratio first crops the largest rectangle of that ratio from the source display coordinates at the anchor position, then fits it inside the frame using contain. Top-left position=(frame dimension−rendered dimension)×anchor. Rendered regions outside the frame are crop; empty regions inside are padding. An inverse EXIF transform returns continuous source coordinates. Display uses up to 6 decimal places. The integer-pixel crop rectangle rounds its start down and its end up, then subtracts edges to obtain width and height; only boundary floating-point noise is corrected. No pixel colors or actual images are transformed.
Worked example (hypothetical values)
For a 400×200 px source, a 100×100 px frame, anchors 0.5/0.5, pixel aspect ratio 1 and EXIF orientation 1: contain renders 100×50 px with 25 px padding at top and bottom; cover renders 200×100 px and crops 50 px on each horizontal side. The source crop rectangle is x=100, y=0, width=200, height=200 px.
Applicability and limitations
Raster images with known positive-integer width and height, and rectangular frames. The display ratio can be corrected when pixel width divided by pixel height is known. Does not crop or save actual images, recompress or load image files, calculate DPI or physical print size, perform interpolation, blur or color processing, or implement CSS fill/none/scale-down. A fixed crop ratio is not a CSS object-fit value.
Method and sources
Method: CSS Images 3 CRD 2023-12-18 / CIPA Exif 2.3 DC-008-2012 orientation / geometry v1.0 (2026-11-14). Data recorded: 2026-11-14.