What is the main issue with calculating the correct aspect ratio when scaling images in PHP?

The main issue with calculating the correct aspect ratio when scaling images in PHP is that simply dividing the new width by the original width may result in distorted images. To solve this issue, you need to calculate the aspect ratio of the original image and use it to determine the new height based on the new width.

// Calculate aspect ratio
$originalWidth = 800;
$originalHeight = 600;
$newWidth = 400;

$aspectRatio = $originalWidth / $originalHeight;
$newHeight = $newWidth / $aspectRatio;

// Display the new dimensions
echo "New Width: " . $newWidth . "px<br>";
echo "New Height: " . $newHeight . "px";