This Package Help You To Connect To Microsoft Face APi by Mohammad Najafian
composer require ikosar/lmfa php artisan vendor:publish
Open lmfa.php in config folder in laravel root then you can enter you'r api_key in this file !
$face = new CheckFace();
if you want to customize the url , Do this π― : (default : https://westcentralus.api.cognitive.microsoft.com/face/v1.0/detect)
$face->setUrl($url);
To this step we set the request's type (only lowercase) :
$face->setMethod("post");
We Must to set headers to use Microsoft's Face APi (only lowercase) :
$face->getApiKey();
$face->setHeaders(array( 'Content-Type' => 'application/json', 'Ocp-Apim-Subscription-Key' => $face->getApiKey(), ));
To this step we can set the Parameters :
$face->setParameters(array( 'returnFaceId' => 'true', // Recommended : True 'returnFaceLandmarks' => 'false', // Very information about face sizes 'returnFaceAttributes' => 'age,gender,glasses,smile,noise,hair,accessories,emotion,makeup', // Your Requsted info ));
You can set these in the returnFaceAttributes in parameters Some Face Attributes : age , gender , glasses , smile , noise , hair , accessories , emotion , makeup ... //
Then , we need to set image :-) : We must to put image URL in the array Like This.
$image = array( 'url' => 'http://cdn-tehran.wisgoon.com/dlir-s3/10531466806488528869.JPG', ); $face->setBody($image,true); // Set Image
We must to Check Before $face->send().
$face->check(); $face->send();
Do This :
$face->check(); $result = $face->send(); // Now JSON in $result return $result;
$image = array( 'url' => 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d2/Donald_Trump_August_19%2C_2015_%28cropped%29.jpg/245px-Donald_Trump_August_19%2C_2015_%28cropped%29.jpg', ); $url = "http://..."; $face = new CheckFace(); $face->setUrl($url); $face->setImage($image); $face->setMethod("post"); $face->setHeaders(array( 'Content-Type' => 'application/json', 'Ocp-Apim-Subscription-Key' => $face->getApiKey(), )); $face->setParameters(array( 'returnFaceId' => 'true', 'returnFaceLandmarks' => 'false', 'returnFaceAttributes' => 'age,gender,glasses,smile,noise,hair,accessories,emotion,makeup', )); $face->setBody($image); $face->check(); $result = $face->send();
##Licence This Project is under the MIT Licence ##Read About Microsoft Face Api ###Types of requests
https://westcentralus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236