How to Remove EXIF Data from Images in PHP
1 min readMar 2, 2023
While EXIF data certainly contains useful information, it sometimes constitutes a privacy concern — so building EXIF removal into your applications is always helpful. You can easily implement an EXIF removal API using the PHP code provided below — just copy and paste, provide a free-tier API key with your request (get one here), and you’ll be done in seconds.
To begin, run this command to install the SDK:
composer require cloudmersive/cloudmersive_imagerecognition_api_client
After that, use the remaining code to call the function:
<?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\EditApi(
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->editRemoveExifData($image_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EditApi->editRemoveExifData: ', $e->getMessage(), PHP_EOL;
}
?>
That’s all there is to it! No more code required.