Skip to content
🛠️ToolsShed

Aspect Ratio Calculator

Calculate aspect ratios and scale dimensions while maintaining proportions.

About this tool

An aspect ratio is the proportional relationship between width and height of an image, screen, or any rectangular shape. The Aspect Ratio Calculator helps you maintain this proportion when resizing content—whether you're scaling images for web, fitting videos to different screens, or designing layouts. It's essential for photographers, videographers, web designers, and anyone who needs to preserve image quality and composition during resizing.

Using the calculator is straightforward: enter the original width and height, then input either a new width or height, and the tool automatically calculates the missing dimension while preserving the aspect ratio. You can also swap units or reverse dimensions if needed. This method ensures your content scales perfectly without distortion—critical for responsive design, social media graphics, or maintaining cinema formats across different platforms.

The calculator works with any measurement unit (pixels, inches, centimeters) and handles both landscape and portrait orientations. It's particularly useful for creating multiple versions of the same asset—thumbnails from high-resolution originals, banner designs for various social platforms, or video exports in different resolutions. Understanding your content's aspect ratio upfront prevents awkward cropping or stretching that degrades visual quality.

Frequently Asked Questions

Code Implementation

import math

def simplify_ratio(width: int, height: int) -> tuple[int, int]:
    """Simplify a width:height pair to its lowest integer ratio using GCD."""
    g = math.gcd(width, height)
    return width // g, height // g

def scale_to_width(orig_w: int, orig_h: int, new_w: int) -> float:
    """Calculate new height given new width, preserving aspect ratio."""
    return new_w * (orig_h / orig_w)

def scale_to_height(orig_w: int, orig_h: int, new_h: int) -> float:
    """Calculate new width given new height, preserving aspect ratio."""
    return new_h * (orig_w / orig_h)

def ratio_decimal(width: int, height: int) -> float:
    """Return aspect ratio as a decimal (e.g. 1.778 for 16:9)."""
    return width / height

# Examples
w, h = simplify_ratio(1920, 1080)
print(f"1920:1080 → {w}:{h}")          # 16:9

w, h = simplify_ratio(1280, 720)
print(f"1280:720  → {w}:{h}")          # 16:9

w, h = simplify_ratio(800, 600)
print(f"800:600   → {w}:{h}")          # 4:3

w, h = simplify_ratio(3840, 2160)
print(f"3840:2160 → {w}:{h}")          # 16:9 (4K)

# Scale operations
new_h = scale_to_width(1920, 1080, 1280)
print(f"1920×1080 → width 1280 → height {new_h:.0f}")   # 720

new_w = scale_to_height(1920, 1080, 720)
print(f"1920×1080 → height 720 → width {new_w:.0f}")    # 1280

# Batch simplification
resolutions = [(1920, 1080), (1280, 720), (3840, 2160), (2560, 1440), (800, 600)]
for rw, rh in resolutions:
    sw, sh = simplify_ratio(rw, rh)
    print(f"{rw}×{rh} = {sw}:{sh} ({ratio_decimal(rw, rh):.3f})")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.