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
| Ratio | Decimal | Common Uses |
|---|---|---|
| 16:9 | 1.778 | HD Video, Monitors, Dashboard cards |
| 4:3 | 1.333 | Legacy displays, Documents |
| 1:1 | 1.000 | Thumbnails, Profile images |
| 3:2 | 1.500 | Photography, DSLR sensors |
| 21:9 | 2.333 | Ultrawide monitors |
| A4 | 1.414 | Print 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
| Format | Bytes/Pixel | Notes |
|---|---|---|
| RGB (24-bit) | 3 | Standard color |
| RGBA (32-bit) | 4 | With transparency |
| Grayscale (8-bit) | 1 | Black & white |
Example: 1920×1080 RGBA image
Size = 1920 × 1080 × 4 = 8,294,400 bytes ≈ 7.9 MB
Compressed Size Estimates
| Format | Typical Compression | Best For |
|---|---|---|
| JPEG (quality 80) | 10:1 to 20:1 | Photos, complex images |
| PNG | 2:1 to 5:1 | Graphics, screenshots, transparency |
| WebP | 25:1 to 35:1 | Web images (modern browsers) |
| SVG | N/A | Icons, 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
| DPI | Use Case |
|---|---|
| 72 | Screen/web (legacy) |
| 96 | Windows default screen |
| 150 | Draft print quality |
| 300 | Standard print quality |
| 600 | High 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.