Remove Image background with php and save transparent png

后端 未结 7 1259
心在旅途
心在旅途 2020-12-15 01:23

I want to remove the white background of any image uploaded on the site working on PHP platform. The uploading function is done but messed up with this functionality.

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 02:15

    function transparent_background($filename, $color) 
    {
        $img = imagecreatefrompng('image.png'); //or whatever loading function you need
        $colors = explode(',', $color);
        $remove = imagecolorallocate($img, $colors[0], $colors[1], $colors[2]);
        imagecolortransparent($img, $remove);
        imagepng($img, $_SERVER['DOCUMENT_ROOT'].'/'.$filename);
    }
    
    transparent_background('logo_100x100.png', '255,255,255');
    

提交回复
热议问题