Skip to content
Laravel + AWS SDK for PHP Rekognition Integration
Branch: master
Clone or download
icweb Merge pull request #1 from csgt/master
Fix to TextDetection documentation
Latest commit cf17c6e Apr 18, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app Removed redundant credentials Sep 10, 2018
bootstrap first commit Sep 9, 2018
config first commit Sep 9, 2018
database Removed stuff that is for demo only Sep 9, 2018
public first commit Sep 9, 2018
resources Removed font awesome cdn Sep 10, 2018
routes first commit Sep 9, 2018
storage first commit Sep 9, 2018
tests first commit Sep 9, 2018
.editorconfig first commit Sep 9, 2018
.gitattributes first commit Sep 9, 2018
.gitignore first commit Sep 9, 2018
README.md Fix to TextDetection documentation Mar 1, 2019
artisan first commit Sep 9, 2018
composer.json first commit Sep 9, 2018
composer.lock first commit Sep 9, 2018
package.json first commit Sep 9, 2018
phpunit.xml first commit Sep 9, 2018
server.php first commit Sep 9, 2018
webpack.mix.js first commit Sep 9, 2018
yarn.lock first commit Sep 9, 2018

README.md

Laravel + AWS Rekognition Integration

This project demonstrates the integration of the AWS SDK for PHP Rekognition client into a Laravel project, covering two functions of the Rekognition service: detecting text in photos, and detecting nudity. This project is a demonstration and requires you to integrate your own use case.

View Demo


Prerequisites

AWS Account & Access Keys

You will need to get your AWS Secret Access Key and Access Key ID to use the SDK. Click here to visit the Managing Access Keys for IAM Users page and learn how to find these keys.

About Rekognition


Installation

Begin by installing the AWS SDK for PHP package with Composer. Edit your composer.json file to require aws/aws-sdk-php version 3.

"require": {
  "aws/aws-sdk-php": "3.*"
}

Then update your project by running this command in your terminal at your project root.

composer update

Configuration

Add two new environment variables to your .env file and populate the values with your keys found in the prerequisites section.

AWS_SECRET_ACCESS_KEY=ENTER_YOUR_KEY
AWS_ACCESS_KEY_ID=ENTER_YOUR_KEY

Usage

Create the Client

Create a new RekognitionClient and fill in your region to begin making requests.

use Aws\Rekognition\RekognitionClient;

$client = new RekognitionClient([
    'region'    => 'ENTER_YOUR_REGION',
    'version'   => 'latest'
]);

Preparing the Image

Convert the uploaded file into base64-encoded image bytes.

$image = fopen($request->file('photo')->getPathName(), 'r');
$bytes = fread($image, $request->file('photo')->getSize());

Create the Request

Create a request to Rekognition. Supply the image bytes, and enter a minimum confidence level for your labels.

Detect Nudity

$results = $client->detectModerationLabels([
    'Image'         => ['Bytes' => $bytes],
    'MinConfidence' => 50
])['ModerationLabels'];

# Check to see if nudity labels were returned
$containsNudity = array_search('Explicit Nudity', array_column($results, 'Name'));

Detect Text in Photo

$results = $client->detectText([
    'Image'         => ['Bytes' => $bytes],
])['TextDetections'];

# Create single string of all words detected
foreach($results as $item)
{
   if($item['Type'] === 'WORD')
   {
       $string .= $item['DetectedText'] . ' ';
   }
}
You can’t perform that action at this time.