Commit 39631691 authored by Okthane's avatar Okthane

okay

parent 46dc8baf
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="style.css"> <link rel="stylesheet" type="text/css" href="style.css">
<!-- Si souhaitez utiliser le code en local -->
<script src="tensorflow.js"></script> <!-- <script src="tensorflow.js"></script> -->
<script src="blazeface.js"></script> <!-- <script src="blazeface.js"></script> -->
<!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script> --> <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<!-- <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/blazeface"></script> --> <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/blazeface"></script>
<script src="jquery.js"></script> <script src="jquery.js"></script>
<script src="script.js"></script> <script src="script.js"></script>
<title>Formulaire d'upload de fichiers</title> <title>Formulaire d'upload de fichiers</title>
...@@ -58,7 +58,9 @@ ...@@ -58,7 +58,9 @@
<div id ="dropcontainer" class ="row d-flex justify-content-center div-ID div-photo" > <div id ="dropcontainer" class ="row d-flex justify-content-center div-ID div-photo" >
<div class="col-md-3 my-auto d-flex justify-content-center" > <div class="col-md-3 my-auto d-flex justify-content-center" >
<img name ="im-ID" id="img-ID" src="" height="150em"/> <img name ="im-ID" id="img-ID" src="" height="150em"/>
<!-- <canvas id="ctx"></canvas> -->
</div> </div>
<div id=conditions class="col-md-3 my-5 d-flex justify-content-center"> <div id=conditions class="col-md-3 my-5 d-flex justify-content-center">
<ul class="list-group"> <ul class="list-group">
...@@ -87,9 +89,9 @@ ...@@ -87,9 +89,9 @@
</form> </form>
<script> <script>
const inpFile = document.getElementById("fileUpload"); const inpFile = document.getElementById("fileUpload");
const previewImage = document.getElementById("img-ID"); const previewImage = document.getElementById("img-ID");
const file = inpFile.files[0]; const file = inpFile.files[0];
console.log("ok"); console.log("ok");
if (file){ if (file){
const reader = new FileReader(); const reader = new FileReader();
......
{"errors":[{"title":"No image given","code":"missing_source","detail":"Please provide the source image in the image_url, image_file or image_file_b64 parameter."}]}
\ No newline at end of file
<?php <?php
// phpinfo(); // phpinfo();
// die; define('PATH', "img_bg");
define('WHERE_TO_PUT','img_bg'); define('KEY' ,'n6CkFXudANRCubRKMKG5hjNa');
define('PATH_TO_BG', "img_bg");
define('TEMP','temp');
define('KEY','n6CkFXudANRCubRKMKG5hjNa');
require_once "vendor/autoload.php"; require_once "vendor/autoload.php";
...@@ -17,15 +14,15 @@ if($_SERVER["REQUEST_METHOD"] == "POST") ...@@ -17,15 +14,15 @@ if($_SERVER["REQUEST_METHOD"] == "POST")
"jpg" => "image/jpeg", "jpg" => "image/jpeg",
"png" => "image/png" "png" => "image/png"
); );
$filename = $_FILES["photo"]["name"]; $filename = $_FILES["photo"]["name"];
$newfilename = $filename; $newfilename = $filename;
$filetype = $_FILES["photo"]["type"]; $filetype = $_FILES["photo"]["type"];
$ext = pathinfo($filename, PATHINFO_EXTENSION); $ext = pathinfo($filename, PATHINFO_EXTENSION);
if(array_key_exists($ext, $allowed)) if(array_key_exists($ext, $allowed))
{ {
$client = new GuzzleHttp\Client(["verify"=>false]); $client = new GuzzleHttp\Client(["verify"=>false]);
$res = $client->post('https://api.remove.bg/v1.0/removebg', [ $res = $client->post('https://api.remove.bg/v1.0/removebg', [
'multipart' => [ 'multipart' => [
[ [
'name' => 'image_file', 'name' => 'image_file',
...@@ -40,20 +37,22 @@ if($_SERVER["REQUEST_METHOD"] == "POST") ...@@ -40,20 +37,22 @@ if($_SERVER["REQUEST_METHOD"] == "POST")
'X-Api-Key' => KEY 'X-Api-Key' => KEY
] ]
]); ]);
// On supprime l'image intermédiaire
// $deletefile=unlink(TEMP.'/'.$newfilename);
$path = PATH.'/'.pathinfo($newfilename, PATHINFO_FILENAME)."NO-BG.png";
//On crée et stocke l'image détourée //On crée et stocke l'image détourée
$fp = fopen('img_bg/'.pathinfo($newfilename, PATHINFO_FILENAME)."NO-BG.png", "wb"); $fp = fopen($path, "wb");
fwrite($fp, $res->getBody()); fwrite($fp, $res->getBody());
fclose($fp); fclose($fp);
$path = 'img_bg/'.pathinfo($filename, PATHINFO_FILENAME)."NO-BG.png"; //On renvoie l'image détourée au front
$type = pathinfo($path, PATHINFO_EXTENSION); // $path = 'img_bg'.'/'.pathinfo($filename, PATHINFO_FILENAME)."NO-BG.png";
$data = file_get_contents($path); $type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data); $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
$data = array( $data = array(
"témoin"=>"ok",
"src" => $base64 "src" => $base64
); );
echo json_encode($data); echo json_encode($data);
......
This diff is collapsed.
...@@ -11,20 +11,21 @@ if($_SERVER["REQUEST_METHOD"] == "POST") ...@@ -11,20 +11,21 @@ if($_SERVER["REQUEST_METHOD"] == "POST")
if(isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0) if(isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0)
{ {
$allowed = array( $allowed = array(
"jpg" => "image/jpeg", "jpg" => "image/jpeg",
"jpeg" => "image/jpeg", "jpeg" => "image/jpeg",
"png" => "image/png", "png" => "image/png",
"PNG" => "image/PNG", "PNG" => "image/PNG",
"JPG" => "image/JPG" "JPG" => "image/JPG"
); );
$filename = htmlspecialchars(trim($_FILES["photo"]["name"]));// évite les noms de fichiers trop exotiques $filename = htmlspecialchars(trim($_FILES["photo"]["name"]));// évite les noms de fichiers trop exotiques
$newfilename = $filename; $newfilename = $filename;
$filetype = $_FILES["photo"]["type"]; $filetype = $_FILES["photo"]["type"];
$filesize = $_FILES["photo"]["size"]; $filesize = $_FILES["photo"]["size"];
$message = ""; $message = "";
$error = true;
$errorSize = true; $error = true;
$errorMIME = true; $errorSize = true;
$errorMIME = true;
// Vérifie l'extension du fichier // Vérifie l'extension du fichier
$ext = pathinfo($filename, PATHINFO_EXTENSION); $ext = pathinfo($filename, PATHINFO_EXTENSION);
...@@ -47,7 +48,7 @@ if($_SERVER["REQUEST_METHOD"] == "POST") ...@@ -47,7 +48,7 @@ if($_SERVER["REQUEST_METHOD"] == "POST")
"errorMIME" => $errorMIME, "errorMIME" => $errorMIME,
"errorSize" => $errorSize, "errorSize" => $errorSize,
"error" => $error,//<----- Prend la valeur true (erreur!) ou false (ouf!) "error" => $error,//<----- Prend la valeur true (erreur!) ou false (ouf!)
); );
echo json_encode($data); echo json_encode($data);
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
if($_SERVER["REQUEST_METHOD"]=="POST"){ if($_SERVER["REQUEST_METHOD"]=="POST"){
$data = array( $data = array(
"atraiter" => true, "atraiter" => true,
"studentId" => $_POST['studentId'],
"prenom" => "jean-patrick", "studentId" => $_POST['studentId'],
"nom" => "doe.remifa.sollasi", "prenom" => "jean-patrick",
"nom" => "doe.remifa.sollasi",
"mailCalcule" => "patrick.doe.remifa.sollasi@ext.imt-nord-europe.fr", "mailCalcule" => "patrick.doe.remifa.sollasi@ext.imt-nord-europe.fr",
// "mailsPossibles" => array() // "mailsPossibles" => array()
"mailsPossibles"=>array("jean-patrick.doe@ext.imt-nord-europe.fr","jean.doe@ext.imt-nord-europe.fr","patrick.doe@ext.imt-nord-europe.fr","jean.remifa.sollasi@ext.imt-nord-europe.fr","jp.doeremifasollasi@ext.imt-nord-europe.fr") "mailsPossibles"=>array("jean-patrick.doe@ext.imt-nord-europe.fr","jean.doe@ext.imt-nord-europe.fr","patrick.doe@ext.imt-nord-europe.fr","jean.remifa.sollasi@ext.imt-nord-europe.fr","jp.doeremifasollasi@ext.imt-nord-europe.fr")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment