How to Get Image Metadata in PHP

Cloudmersive
1 min readMar 9, 2023

--

Image files typically contain useful data we can use in downstream operations (such as editing, filtering, etc.). Using the below code, you can call our Image Metadata API and instantly retrieve information including the width, height, bit depth, transparency, color spacing, EXIF values, and more. You can use this API for free by registering a free account on our website (this supplies a free-tier API key which you can copy into your request for authentication).

To install the PHP SDK, run this command:

composer require cloudmersive/cloudmersive_imagerecognition_api_client

Then, to structure your request, use the following code examples:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');



$apiInstance = new Swagger\Client\Api\InfoApi(


new GuzzleHttp\Client(),
$config
);
$image_file = "/path/to/inputfile"; // \SplFileObject | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.

try {
$result = $apiInstance->infoGetMetadata($image_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling InfoApi->infoGetMetadata: ', $e->getMessage(), PHP_EOL;
}
?>

That’s all there is to it. You can now retrieve image medata with ease!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet