From bfa29d239f331daa0440352b0905a5af77cbec5b Mon Sep 17 00:00:00 2001 From: Jared Schoeny Date: Tue, 21 Oct 2025 22:23:21 -1000 Subject: [PATCH] Fix scaling issues with PixelImage --- src/components/PixelImage.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/PixelImage.tsx b/src/components/PixelImage.tsx index fa8ff27..7623331 100644 --- a/src/components/PixelImage.tsx +++ b/src/components/PixelImage.tsx @@ -60,20 +60,18 @@ export default function PixelImage({ src, alt, mode = "cover", className = "", i const ih = naturalSize.height; const cw = containerSize.width; const ch = containerSize.height; - const dpr = devicePixelRatioState || 1; if (iw <= 0 || ih <= 0 || cw <= 0 || ch <= 0) return 1; const scaleX = cw / iw; const scaleY = ch / ih; - const step = 1 / dpr; // CSS-px step that maps to 1 device pixel increment if (mode === "cover") { const required = Math.max(scaleX, scaleY); // Snap UP to the nearest step to ensure we cover the container - return Math.max(step, Math.ceil(required * dpr) / dpr); + return Math.max(1, Math.ceil(required)); } // contain const allowed = Math.min(scaleX, scaleY); // Snap DOWN to nearest step to avoid overflow - return Math.max(step, Math.floor(allowed * dpr) / dpr); + return Math.max(1, Math.floor(allowed)); }, [naturalSize, containerSize, mode, devicePixelRatioState]); const widthPx = naturalSize.width > 0 ? naturalSize.width * scale : undefined;