Same name and namespace in other branches
  1. 7.x-1.x ExifPHPExtension.php \Drupal\exif\ExifPHPExtension::readExifTags() 1 comment
  2. 8.x-2.x src/ExifPHPExtension.php \Drupal\exif\ExifPHPExtension::readExifTags() 1 comment

Read Exif Information from a file.

Parameters

string $file: Path to file.

bool $enable_sections: Indicate if the information is retrieve by sections or flatten.

Return value

array Values by key and optionally sections.

1 call to ExifPHPExtension::readExifTags()
ExifPHPExtension::readMetadataTags in src/ExifPHPExtension.php
Read all metadata tags.

File

src/ExifPHPExtension.php, line 155

Class

ExifPHPExtension
Class ExifPHPExtension Parser implementation base d on PHP Exif extension.

Namespace

Drupal\exif

Code

public function readExifTags($file, $enable_sections = TRUE) {
    $ar_supported_types = [
        'jpg',
        'jpeg',
    ];
    if (!in_array(strtolower($this->getFileType($file)), $ar_supported_types)) {
        return [];
    }
    $exif = [];
    try {
        $exif = @exif_read_data($file, 0, $enable_sections);
    } catch (\Exception $e) {
        // Logs a notice.
        Drupal::logger('exif')->warning(t("Error while reading EXIF tags from image."), $e);
    }
    $arSmallExif = [];
    foreach ((array) $exif as $key1 => $value1) {
        if (is_array($value1)) {
            foreach ((array) $value1 as $key3 => $value3) {
                $value[strtolower($key3)] = $value3;
            }
        }
        else {
            $value = $value1;
        }
        $arSmallExif[strtolower($key1)] = $value;
    }
    return $arSmallExif;
}