How to generate an English text description of an image in PHP

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:

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(),
$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);
} 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.

Image for post

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store