diff --git a/src/components/image-converter.tsx b/src/components/image-converter.tsx index 91eeb9b..1d0f0c9 100644 --- a/src/components/image-converter.tsx +++ b/src/components/image-converter.tsx @@ -294,11 +294,28 @@ export function ImageConverter() { const handleAspectRatioChange = (value: string) => { setAspectRatio(value); - if (value !== 'custom' && width) { - const [w, h] = value.split('/').map(Number); - const newHeight = Math.round(Number(width) * (h / w)); - setHeight(newHeight); + + if (value === "custom") { + return; } + + const [w, h] = value.split("/").map(Number); + let newWidth: number; + let newHeight: number; + + if (w > h) { + newWidth = 1000; + newHeight = Math.round((1000 * h) / w); + } else if (h > w) { + newHeight = 1000; + newWidth = Math.round((1000 * w) / h); + } else { + newWidth = 1000; + newHeight = 1000; + } + + setWidth(newWidth); + setHeight(newHeight); }; const handleWidthChange = (e: React.ChangeEvent) => { @@ -315,7 +332,7 @@ export function ImageConverter() { return (
-
+