How to generate an English text description of an image in PHP
1 min readAug 6, 2019
Today we shall demonstrate an easy way to automatically create full sentence descriptions of any image using one of our APIs. Let us begin by installing our image processing API using the command line in Composer:
composer require cloudmersive/cloudmersive_imagerecognition_api_client
All that remains is to call recognizeDescribe:
<?php
require_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\RecognizeApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$image_file = "/path/to/file.txt"; // \SplFileObject | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.try {
$result = $apiInstance->recognizeDescribe($image_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling RecognizeApi->recognizeDescribe: ', $e->getMessage(), PHP_EOL;
}
?>
Our API will then generate a one-sentence description of your image. It’s that easy.