Php 调整图像大小时,在imagefill之前,将图像居中

Php 调整图像大小时,在imagefill之前,将图像居中,php,Php,我对php是新手,实际上对所有东西都是新手。如何在imagefill之前将图像居中?现在,如果比率小于新比率,则图像将转到左侧,并且右侧的所有内容都填充为白色 我尝试了imagecopyresampled($tn,$img_source,0,0,$new_width/2,0,$new_width,$new_height,$width,$height)好吧,这只是把所有的东西都削减了一半 if ( $image_ratio <= $mod_ratio ){

我对php是新手,实际上对所有东西都是新手。如何在imagefill之前将图像居中?现在,如果比率小于新比率,则图像将转到左侧,并且右侧的所有内容都填充为白色

我尝试了
imagecopyresampled($tn,$img_source,0,0,$new_width/2,0,$new_width,$new_height,$width,$height)好吧,这只是把所有的东西都削减了一半

    if ( $image_ratio <= $mod_ratio ){
                $new_height = $mod_height;
                $new_width = $width / ($height / $mod_height);
            }
            else {
                $new_width = $mod_width;
                $new_height = $height / ($width / $mod_width);
            }

//blah blah         
            $tn= imagecreatetruecolor($mod_width, $mod_height);
            $whiteBackground = imagecolorallocate($tn, 255, 255, 255);
            imagefill($tn,0,0,$whiteBackground); 
            imagecopyresampled($tn, $img_source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if($image\u比率