$height) {
$new_width = $max_width;
$new_height = ($height / $width) * $max_width;
} else {
$new_height = $max_height;
$new_width = ($width / $height) * $max_height;
}
// Create the output image
$output_image = imagecreatetruecolor($new_width, $new_height);
// Resize the input image to the new dimensions and copy to output image
imagecopyresampled($output_image, $input_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Save the output image to file
imagejpeg($output_image, $output_file);
// Free up memory by destroying the images
imagedestroy($input_image);
imagedestroy($output_image);
?>
Resized Image