Last active
June 7, 2017 01:34
-
-
Save joetannenbaum/aa7b9eeb2fcc52df4e7401b855ff2da1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$faces = collect($result->get('FaceDetails') ?: [])->filter(function ($face) { | |
// We want to be fairly confident that we found a face | |
return $face['Confidence'] > 95; | |
}); | |
$box = $faces->first()['BoundingBox']; | |
// Where the center of the face sits in relation to the entire image | |
$center_percentage = [ | |
'x' => round(($box['Left'] + ($box['Width'] / 2)) * 100), | |
'y' => round(($box['Top'] + ($box['Height'] / 2)) * 100), | |
]; | |
// The pixel coordinates of the center of the face | |
$center_position = [ | |
'x' => round($image->width * ($center_percentage['x'] / 100)), | |
'y' => round($image->height * ($center_percentage['y'] / 100)), | |
]; | |
// The pixel dimensions of the face | |
$face_dimensions = [ | |
'width' => round($image->width * $box['Width']), | |
'height' => round($image->height * $box['Height']), | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment