-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageage.php
44 lines (36 loc) · 1.23 KB
/
imageage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
// Replace with your Azure Face API subscription key and endpoint
$subscriptionKey = 'YOUR_SUBSCRIPTION_KEY';
$endpoint = 'YOUR_API_ENDPOINT';
$imageUrl = 'https://example.com/path/to/your/image.jpg';
// Azure Face API URL for age detection
$url = $endpoint . '/face/v1.0/detect';
// Request parameters
$params = array(
'returnFaceAttributes' => 'age',
);
// Prepare the HTTP headers
$headers = array(
'Content-Type: application/json',
'Ocp-Apim-Subscription-Key: ' . $subscriptionKey,
);
// Create the POST request to the API
$ch = curl_init($url . '?' . http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array('url' => $imageUrl)));
// Execute the request and get the response
$response = curl_exec($ch);
curl_close($ch);
// Parse the response
$data = json_decode($response, true);
// Check if the response contains face attributes
if (isset($data[0]['faceAttributes']['age'])) {
$age = $data[0]['faceAttributes']['age'];
echo "Detected age: $age";
} else {
echo "No faces or age detected in the image.";
}
?>