diff --git a/src/components/tools/DynamicToolWorkspace.tsx b/src/components/tools/DynamicToolWorkspace.tsx index 4113fdb..7c94bcc 100644 --- a/src/components/tools/DynamicToolWorkspace.tsx +++ b/src/components/tools/DynamicToolWorkspace.tsx @@ -463,7 +463,7 @@ export function DynamicToolWorkspace({ beforeUrl={comparisonBeforeUrl || primaryPreview || primaryExample.before} afterUrl={resultUrl} title={toolName} - aspectRatio="aspect-auto" + aspectRatio="aspect-[4/3] sm:aspect-[16/10]" objectFit="contain" beforeLabel="ORIGINAL" afterLabel="RESULT" diff --git a/src/components/ui/CardBeforeAfterSlider.tsx b/src/components/ui/CardBeforeAfterSlider.tsx index 4178638..dcd04fb 100644 --- a/src/components/ui/CardBeforeAfterSlider.tsx +++ b/src/components/ui/CardBeforeAfterSlider.tsx @@ -49,6 +49,29 @@ export function CardBeforeAfterSlider({ } }; + // Proactively measure image natural dimensions to prevent zero-height collapse + useEffect(() => { + if (!afterUrl && !beforeUrl) return; + const targetUrl = afterUrl || beforeUrl; + let isCancelled = false; + + const img = new Image(); + img.onload = () => { + if (!isCancelled && img.naturalWidth && img.naturalHeight) { + setNaturalDimensions({ width: img.naturalWidth, height: img.naturalHeight }); + } + }; + img.src = targetUrl; + + if (img.complete && img.naturalWidth && img.naturalHeight) { + setNaturalDimensions({ width: img.naturalWidth, height: img.naturalHeight }); + } + + return () => { + isCancelled = true; + }; + }, [afterUrl, beforeUrl]); + // Smooth gentle oscillation: runs on desktop when hovered before user manually drags useEffect(() => { let startTime: number | null = null; @@ -147,7 +170,7 @@ export function CardBeforeAfterSlider({ }; const imgFitClass = objectFit === 'contain' ? 'object-contain object-center' : 'object-cover'; - const containerAspectClass = naturalDimensions ? '' : aspectRatio; + const containerAspectClass = naturalDimensions ? '' : (aspectRatio === 'aspect-auto' ? 'aspect-[4/3] sm:aspect-[16/10]' : aspectRatio); return (