Documentation

Client
in package

Amazon Rekognition API client wrapper.

Provides simplified interface for AWS Rekognition face detection and comparison. Supports face collections, face matching, and face detection operations.

Usage:

$client = new Client([
  'key' => 'AWS_ACCESS_KEY',
  'secret' => 'AWS_SECRET_KEY',
  'region' => 'ap-northeast-1'
]);

// Add face to collection
$faceId = $client->addFaceToCollection('my-collection', $imageDataUrl);

// Search for similar faces
$match = $client->getFaceFromCollectionByImage('my-collection', $searchImage);

Table of Contents

Properties

$client  : RekognitionClient
RekognitionClient instance.
$debug  : bool
Debug mode.

Methods

__construct()  : mixed
Initialize Amazon Rekognition API client.
addCollection()  : void
Create a face collection.
addFaceToCollection()  : string
Add a face to a collection.
compareFaces()  : float
Compare two face images for similarity.
deleteCollection()  : void
Delete a face collection.
deleteFaceFromCollection()  : void
Delete faces from a collection.
detectionFaces()  : array<string|int, array<string|int, mixed>>
Detect faces in an image.
existsCollection()  : bool
Check if a face collection exists.
existsFaceFromCollection()  : bool
Check if a matching face exists in a collection.
generateCollectionId()  : string
Generate a unique collection ID.
getAllCollections()  : array<string|int, string>
List all face collection IDs.
getAllFacesFromCollection()  : array<string|int, array<string|int, mixed>>
List all faces in a collection.
getCollection()  : array<string|int, mixed>|null
Describe a face collection.
getFaceFromCollectionByImage()  : array{faceId: string, similarity: float}|null
Search for the most similar face in a collection.
getMultipleFacesFromCollectionByImage()  : array<string|int, array{faceId: string, similarity: float}>
Search for all similar faces in a collection.
getNumberOfFaces()  : int
Count the number of faces detected in an image.

Properties

$client

RekognitionClient instance.

private RekognitionClient $client

$debug

Debug mode.

private bool $debug

Methods

__construct()

Initialize Amazon Rekognition API client.

public __construct(array{region?: string, key: string, secret: string, connect_timeout?: int, debug?: bool} $options) : mixed
Parameters
$options : array{region?: string, key: string, secret: string, connect_timeout?: int, debug?: bool}

Configuration options:

  • region: AWS region to connect to. Default is "ap-northeast-1".
  • key: (required) AWS access key ID.
  • secret: (required) AWS secret access key.
  • connect_timeout: Connection timeout in seconds. Default is 5.
  • debug: Output Rekognition responses to debug log. Default is false.
Tags
throws
RuntimeException

If key or secret is not provided.

addCollection()

Create a face collection.

public addCollection(string $collectionId) : void

If the collection already exists, this method does nothing.

Parameters
$collectionId : string

Collection ID.

Tags
throws
RuntimeException

If creation fails for reasons other than duplicate.

throws
RekognitionException

On AWS API error.

addFaceToCollection()

Add a face to a collection.

public addFaceToCollection(string $collectionId, string $faceImage) : string

The image must contain exactly one face.

Parameters
$collectionId : string

Collection ID.

$faceImage : string

Face image as Data URL, binary blob, or file path.

Tags
throws
RuntimeException

If no face or multiple faces are detected, or indexing fails.

Return values
string

Unique face ID assigned by Rekognition.

compareFaces()

Compare two face images for similarity.

public compareFaces(string $faceImage1, string $faceImage2) : float

Returns 0.0 if no face is detected in either image.

Parameters
$faceImage1 : string

Source face image as Data URL, binary blob, or file path.

$faceImage2 : string

Target face image as Data URL, binary blob, or file path.

Tags
throws
RuntimeException

If comparison fails.

Return values
float

Similarity percentage (0.0 to 100.0) between the two faces.

deleteCollection()

Delete a face collection.

public deleteCollection(string $collectionId) : void

If the collection does not exist, this method does nothing.

Parameters
$collectionId : string

Collection ID.

Tags
throws
RuntimeException

If deletion fails.

throws
RekognitionException

On AWS API error.

deleteFaceFromCollection()

Delete faces from a collection.

public deleteFaceFromCollection(string $collectionId, array<string|int, string> $faceIds) : void
Parameters
$collectionId : string

Collection ID.

$faceIds : array<string|int, string>

Array of face IDs to delete.

Tags
throws
RuntimeException

If deletion fails.

detectionFaces()

Detect faces in an image.

public detectionFaces(string $faceImage[, int $threshold = 90 ][, "DEFAULT"|"ALL" $attributes = 'DEFAULT' ]) : array<string|int, array<string|int, mixed>>
Parameters
$faceImage : string

Face image as Data URL, binary blob, or file path.

$threshold : int = 90

Minimum confidence percentage for face detection. Default is 90.

$attributes : "DEFAULT"|"ALL" = 'DEFAULT'

Detail level. "ALL" returns full facial analysis. Default is "DEFAULT".

Tags
throws
RuntimeException

If detection fails.

Return values
array<string|int, array<string|int, mixed>>

Array of detected face details above the confidence threshold.

existsCollection()

Check if a face collection exists.

public existsCollection(string $collectionId) : bool
Parameters
$collectionId : string

Collection ID.

Return values
bool

True if the collection exists.

existsFaceFromCollection()

Check if a matching face exists in a collection.

public existsFaceFromCollection(string $collectionId, string $faceImage[, int $threshold = 80 ]) : bool
Parameters
$collectionId : string

Collection ID.

$faceImage : string

Face image as Data URL, binary blob, or file path.

$threshold : int = 80

Minimum similarity percentage. Default is 80.

Return values
bool

True if a matching face is found.

generateCollectionId()

Generate a unique collection ID.

public generateCollectionId() : string
Return values
string

Randomly generated collection ID.

getAllCollections()

List all face collection IDs.

public getAllCollections() : array<string|int, string>
Tags
throws
RuntimeException

If retrieval fails.

Return values
array<string|int, string>

Array of collection IDs.

getAllFacesFromCollection()

List all faces in a collection.

public getAllFacesFromCollection(string $collectionId[, int $maxResults = 4096 ]) : array<string|int, array<string|int, mixed>>
Parameters
$collectionId : string

Collection ID.

$maxResults : int = 4096

Maximum number of faces to retrieve. Default is 4096.

Tags
throws
RuntimeException

If retrieval fails.

Return values
array<string|int, array<string|int, mixed>>

Array of face metadata from the collection.

getCollection()

Describe a face collection.

public getCollection(string $collectionId) : array<string|int, mixed>|null
Parameters
$collectionId : string

Collection ID.

Tags
throws
RuntimeException

If retrieval fails.

throws
RekognitionException

On AWS API error.

Return values
array<string|int, mixed>|null

Collection metadata, or null if not found.

getFaceFromCollectionByImage()

Search for the most similar face in a collection.

public getFaceFromCollectionByImage(string $collectionId, string $faceImage[, int $threshold = 80 ]) : array{faceId: string, similarity: float}|null

Returns the single best match above the similarity threshold.

Parameters
$collectionId : string

Collection ID.

$faceImage : string

Face image as Data URL, binary blob, or file path.

$threshold : int = 80

Minimum similarity percentage. Default is 80.

Return values
array{faceId: string, similarity: float}|null

Best match, or null if no match found.

getMultipleFacesFromCollectionByImage()

Search for all similar faces in a collection.

public getMultipleFacesFromCollectionByImage(string $collectionId, string $faceImage[, int $threshold = 80 ][, int $maxFaces = 4096 ]) : array<string|int, array{faceId: string, similarity: float}>

Returns all faces matching above the similarity threshold.

Parameters
$collectionId : string

Collection ID.

$faceImage : string

Face image as Data URL, binary blob, or file path.

$threshold : int = 80

Minimum similarity percentage. Default is 80.

$maxFaces : int = 4096

Maximum number of matches to return. Default is 4096.

Tags
throws
RuntimeException

If search fails.

Return values
array<string|int, array{faceId: string, similarity: float}>

Array of matching faces with similarity scores.

getNumberOfFaces()

Count the number of faces detected in an image.

public getNumberOfFaces(string $faceImage[, int $threshold = 90 ]) : int
Parameters
$faceImage : string

Face image as Data URL, binary blob, or file path.

$threshold : int = 90

Minimum confidence percentage for face detection. Default is 90.

Return values
int

Number of faces detected above the confidence threshold.


        
On this page

Search results