Image Calculator

Calculate image dimensions, aspect ratios, and file sizes for responsive design and report generation.

Purpose

When working with images in reports, dashboards, and responsive layouts, maintaining correct aspect ratios prevents distortion. This calculator helps determine target dimensions and estimate file sizes.

Aspect Ratio Calculations

Finding Aspect Ratio

To find the aspect ratio of an image, divide both dimensions by their Greatest Common Divisor (GCD):

Aspect Ratio = Width : Height (reduced by GCD)

Example: 1920×1080 image

GCD(1920, 1080) = 120
Ratio = 1920/120 : 1080/120 = 16:9

Common Aspect Ratios

RatioDecimalCommon Uses
16:91.778HD Video, Monitors, Dashboard cards
4:31.333Legacy displays, Documents
1:11.000Thumbnails, Profile images
3:21.500Photography, DSLR sensors
21:92.333Ultrawide monitors
A41.414Print documents (210×297mm)

Dimension Calculations

Scale to New Width (Preserve Ratio)

New Height = Original Height × (New Width / Original Width)

Example: Scale 1920×1080 to 800px wide

New Height = 1080 × (800 / 1920)
New Height = 1080 × 0.4167
New Height = 450px

Result: 800×450

Scale to New Height (Preserve Ratio)

New Width = Original Width × (New Height / Original Height)

Example: Scale 1920×1080 to 300px tall

New Width = 1920 × (300 / 1080)
New Width = 1920 × 0.278
New Width = 533px

Result: 533×300

Fit Within Container (Preserve Ratio)

To fit an image within a maximum width AND height while preserving aspect ratio:

// Calculate scale factors for both dimensions
scaleW = maxWidth / originalWidth
scaleH = maxHeight / originalHeight

// Use the smaller scale to ensure image fits
scale = MIN(scaleW, scaleH)

newWidth = originalWidth × scale
newHeight = originalHeight × scale

Example: Fit 1920×1080 into 600×400 container

scaleW = 600 / 1920 = 0.3125
scaleH = 400 / 1080 = 0.3704
scale = MIN(0.3125, 0.3704) = 0.3125

newWidth = 1920 × 0.3125 = 600
newHeight = 1080 × 0.3125 = 337

Result: 600×337 (fits within 600×400)

File Size Estimation

Uncompressed Size

Size (bytes) = Width × Height × Bytes per Pixel
FormatBytes/PixelNotes
RGB (24-bit)3Standard color
RGBA (32-bit)4With transparency
Grayscale (8-bit)1Black & white

Example: 1920×1080 RGBA image

Size = 1920 × 1080 × 4 = 8,294,400 bytes ≈ 7.9 MB

Compressed Size Estimates

FormatTypical CompressionBest For
JPEG (quality 80)10:1 to 20:1Photos, complex images
PNG2:1 to 5:1Graphics, screenshots, transparency
WebP25:1 to 35:1Web images (modern browsers)
SVGN/AIcons, logos, scalable graphics

DPI Calculations

Print Size from Pixels

Print Size (inches) = Pixels / DPI

Example: 1920×1080 at 300 DPI

Width = 1920 / 300 = 6.4 inches
Height = 1080 / 300 = 3.6 inches

Required Pixels for Print Size

Pixels = Print Size (inches) × DPI

Example: A4 page at 300 DPI

A4 = 8.27 × 11.69 inches
Width = 8.27 × 300 = 2481 pixels
Height = 11.69 × 300 = 3508 pixels

Standard DPI Values

DPIUse Case
72Screen/web (legacy)
96Windows default screen
150Draft print quality
300Standard print quality
600High quality print

Delphi Helper Function

TYPE
   TImageDimensions = RECORD
      Width: Integer;
      Height: Integer;
   END;

FUNCTION ScaleToFit(OriginalWidth, OriginalHeight, 
   MaxWidth, MaxHeight: Integer): TImageDimensions;
VAR
   ScaleW, ScaleH, Scale: Double;
BEGIN
   ScaleW := MaxWidth / OriginalWidth;
   ScaleH := MaxHeight / OriginalHeight;
   
   IF ScaleW < ScaleH THEN
      Scale := ScaleW
   ELSE
      Scale := ScaleH;
   
   Result.Width := Round(OriginalWidth * Scale);
   Result.Height := Round(OriginalHeight * Scale);
END;
Tip: For responsive dashboard cards, calculate dimensions at design time and store in the database. This avoids layout shifts when images load.