How do I fill white background while resize image

前端 未结 2 1788
执笔经年
执笔经年 2020-12-14 23:04

Current background is black. How to change the color to be white?

    #assuming the mime type is correct
    switch ($imgtype) {
        case \'image/jp         


        
2条回答
  •  無奈伤痛
    2020-12-14 23:38

    $final = imagecreatetruecolor($tn_w, $tn_h);
    $backgroundColor = imagecolorallocate($final, 255, 255, 255);
    imagefill($final, 0, 0, $backgroundColor);
    //imagecopyresampled($final, $newpic, 0, 0, ($x_mid - ($tn_w / 2)), ($y_mid - ($tn_h / 2)), $tn_w, $tn_h, $tn_w, $tn_h);
    imagecopy($final, $newpic, (($tn_w - $new_w)/ 2), (($tn_h - $new_h) / 2), 0, 0, $new_w, $new_h);
    

    Here is your whole script (tested with portrait, landscape and square jpg):

    
    
    

提交回复
热议问题