"image/jpeg", "png" => "image/png" ); $filename = $_FILES["photo"]["name"]; $newfilename = $filename; $filetype = $_FILES["photo"]["type"]; $ext = pathinfo($filename, PATHINFO_EXTENSION); if(array_key_exists($ext, $allowed)) { $client = new GuzzleHttp\Client(["verify"=>false]); $res = $client->post('https://api.remove.bg/v1.0/removebg', [ 'multipart' => [ [ 'name' => 'image_file', 'contents' => fopen($_FILES["photo"]["tmp_name"], 'r') ], [ 'name' => 'size', 'contents' => 'auto' ] ], 'headers' => [ 'X-Api-Key' => KEY ] ]); $path = PATH.'/'.pathinfo($newfilename, PATHINFO_FILENAME)."NO-BG.png"; //On crée et stocke l'image détourée $fp = fopen($path, "wb"); fwrite($fp, $res->getBody()); fclose($fp); //On renvoie l'image détourée au front // $path = 'img_bg'.'/'.pathinfo($filename, PATHINFO_FILENAME)."NO-BG.png"; $type = pathinfo($path, PATHINFO_EXTENSION); $data = file_get_contents($path); $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data); $data = array( "src" => $base64 ); echo json_encode($data); } } } ?>