[PHP]imagescale_output

public function imagescale_output($image_path,$save_path,$width,$height,$aspect_fill = true,$strict_size_on_aspect_fit = true,$space_color = array('r'=>255,'g'=>255,'b'=>255))
{
    if(!is_readable($image_path))
        return false;
    $o_img = $this->imagecreate($image_path);
    $o_w = imagesx($o_img);
    $o_h = imagesy($o_img);
    $w_ratio = $width / $o_w;
    $h_ratio = $height / $o_h;
    $ratio = $aspect_fill ? max($w_ratio,$h_ratio) : min($w_ratio,$h_ratio);
    $new_w = round($o_w * $ratio);
    $new_h = round($o_h * $ratio);
    if(function_exists('imagescale')){
        $new_img = imagescale($o_img,$new_w,$new_h);
    }else{
        $new_img = imagecreatetruecolor($new_w, $new_h);
        imagecopyresampled($new_img, $o_img, 0, 0, 0, 0, $new_w, $new_h, $o_w, $o_h);
    }
    
    $param = $aspect_fill ? array('x' => round(abs($width - $new_w) * 0.5), 'y' => round(abs($height - $new_h) * 0.5), 'width' => $width, 'height' => $height) : array('x' => 0, 'y' => 0, 'width' => $new_w, 'height' => $new_h);
    if(function_exists('imagecrop')) {
        $dest_img = imagecrop($new_img, $param);
    }else{
        $dest_img = imagecreatetruecolor($param['width'], $param['height']);
        imagecopy($dest_img, $new_img, 0, 0, $param['x'], $param['y'], $param['width'], $param['height']);
    }
    imagedestroy($new_img);
    if(!$aspect_fill && $strict_size_on_aspect_fit){
        $next_img = imagecreatetruecolor($width,$height);
        imagefill($next_img,0,0,empty($space_color) ? imagecolorat($dest_img,round($new_w*0.5),0) : imagecolorallocate($dest_img,$space_color['r'],$space_color['g'],$space_color['b']));
        imagecopy($next_img,$dest_img,round(abs($width - $new_w) * 0.5),round(abs($height - $new_h) * 0.5),0,0,$param['width'],$param['height']);
        $success = $this->imageoutput($next_img,$save_path);
        imagedestroy($o_img);
        imagedestroy($next_img);
        imagedestroy($dest_img);
    }else {
        $success = $this->imageoutput($dest_img, $save_path);
        imagedestroy($o_img);
        imagedestroy($dest_img);
    }
    return $success;
}