Remove Image background with php and save transparent png

后端 未结 7 1256
心在旅途
心在旅途 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:25

    Since you only need single-color transparency, the easiest way is to define white with imagecolortransparent(). Something like this (untested code):

    $img = imagecreatefromstring($your_image); //or whatever loading function you need
    $white = imagecolorallocate($img, 255, 255, 255);
    imagecolortransparent($img, $white);
    imagepng($img, $output_file_name);
    

提交回复
热议问题