php-awsHow can I use AWS Textract with PHP?
Using AWS Textract with PHP requires the AWS SDK for PHP.
Once installed, you can use the AWS SDK to call the Textract API. For example, the following code will detect text from an image file:
<?php
require 'vendor/autoload.php';
use Aws\Textract\TextractClient;
$textract = new TextractClient([
'region' => 'us-east-1',
'version' => '2018-06-27'
]);
$result = $textract->detectDocumentText([
'Document' => [
'Bytes' => file_get_contents('image.jpg')
]
]);
print_r($result);
The output of this code will be an array containing the detected text from the image.
The code can also be used to detect text from PDFs. To do this, the PDF will need to be converted to a byte array first.
<?php
require 'vendor/autoload.php';
use Aws\Textract\TextractClient;
$textract = new TextractClient([
'region' => 'us-east-1',
'version' => '2018-06-27'
]);
$pdf_bytes = file_get_contents('document.pdf');
$result = $textract->detectDocumentText([
'Document' => [
'Bytes' => $pdf_bytes
]
]);
print_r($result);
The output of this code will be an array containing the detected text from the PDF.
For more information, see the AWS Textract Documentation.
More of Php Aws
- How can I use PHP to connect to an Amazon Aurora database?
- How do I use PHP to create a ZIP file on AWS?
- How can I use AWS and Zksync together with PHP?
- How can I use Yum to install PHP on an Amazon EC2 instance?
- How can I use an AWS SQS Worker with PHP?
- How can I use AWS WAF to secure my PHP application?
- How can I use AWS PHP SDK without credentials?
- How do I generate an AWS Signature Version 4 with PHP?
- How do I determine the version of PHP I am running on AWS?
- How can I use the AWS S3 S3Client library with PHP?
See more codes...