Skip to main content

How to read EXIF data from an image file

Posted on April 30, 2022

Image files often have embedded metadata in EXIF. Here is one way to read that metadata from an image file that belongs to a media entity of type image.

$media; // this is the media entity object.
$image_file = $media->get('field_media_image')->entity;
$image_file_uri = $image_file->getFileUri();
$image_file_absolute_path = \Drupal::service('file_system')->realpath($image_file_uri);
$exif_data = exif_read_data($image_file_absolute_path);

$exif_data will have the metadata in a list format.