🛠️ToolsShed

ピクセル密度計算機

画面解像度と物理サイズからPPI(ピクセル/インチ)とDPIを計算。

よくある質問

コード実装

import math

def calculate_ppi(width_px: int, height_px: int, diagonal_inches: float) -> float:
    """Calculate PPI from screen resolution and diagonal size."""
    diagonal_px = math.sqrt(width_px**2 + height_px**2)
    return diagonal_px / diagonal_inches

def ppi_to_dpcm(ppi: float) -> float:
    """Convert PPI to dots per centimeter."""
    return ppi / 2.54

def dpcm_to_ppi(dpcm: float) -> float:
    """Convert dots per centimeter to PPI."""
    return dpcm * 2.54

# Common screen PPI calculations
screens = [
    ("iPhone 15 Pro",       2556, 1179, 6.1),
    ("MacBook Pro 14",      3024, 1964, 14.2),
    ('4K 27" Monitor',      3840, 2160, 27.0),
    ('FHD 27" Monitor',     1920, 1080, 27.0),
    ('4K 55" TV',           3840, 2160, 55.0),
]

print(f"{'Screen':<22} {'Resolution':<15} {'Diagonal':>8} {'PPI':>7}  Category")
print("-" * 70)
for name, w, h, d in screens:
    ppi = calculate_ppi(w, h, d)
    category = "Retina (≥220)" if ppi >= 220 else "High-DPI (≥150)" if ppi >= 150 else "Standard"
    print(f"{name:<22} {w}×{h:<9} {d:>6.1f}"  {ppi:>6.1f}  {category}")

# Output:
# iPhone 15 Pro          2556×1179       6.1"   460.4  Retina (≥220)
# MacBook Pro 14         3024×1964      14.2"   253.6  Retina (≥220)
# 4K 27" Monitor         3840×2160      27.0"   163.2  High-DPI (≥150)
# FHD 27" Monitor        1920×1080      27.0"    81.6  Standard
# 4K 55" TV              3840×2160      55.0"    80.1  Standard

Comments & Feedback

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