画像サイズを一定のサイズにリサイズするプログラムを書いてください。
サイズ：400x200
<?php
$target_width = 400; // width of output image 
$target_height = 200; // height of output image 

function image_resize($source_image, $target_width, $target_height){
    $source_image = imagecreatefromstring($source_image);
    
    $source_width = imagesx($source_image);
    $source_height = imagesy($source_image);

    // Calculate new size
    $width_ratio = $target_width / $source_width;
    $height_ratio = $target_height / $source_height;
    $scale = min($width_ratio, $height_ratio);
    
    // Resize image
    $new_width = (int)($source_width * $scale);
    $new_height = (int)($source_height * $scale);
    $tmp_image = imagecreatetruecolor($new_width, $new_height);
    imagecopyresampled($tmp_image, $source_image, 0, 0, 0, 0,
        $new_width, $new_height, $source_width, $source_height);
    
    ob_start();
    imagepng($tmp_image);
    imagedestroy($tmp_image);
    $result_image = ob_get_contents();
    ob_end_clean();

    return $result_image;
}
?>