Skip to content
PHP Logo

How can PHP developers ensure that only the thumbnail EXIF data is removed from an image?

When removing EXIF data from an image in PHP, developers can use the `exif_read_data` function to read the existing EXIF data, unset the unwanted thumbnail data, and then save the modified image without the thumbnail information.

php
// Read the existing EXIF data from the image
$exif = exif_read_data('image.jpg');

// Unset the thumbnail data from the EXIF array
unset($exif['THUMBNAIL']);

// Save the modified image without the thumbnail data
$image = imagecreatefromjpeg('image.jpg');
imagejpeg($image, 'image_no_thumbnail.jpg');

// Optionally, save the modified EXIF data to the new image
if(function_exists('exif_read_data') && function_exists('exif_read_data')) {
    $exif = exif_read_data('image.jpg');
    exif_write_data($exif, 'image_no_thumbnail.jpg');
}