You are here

private function ExifPHPExtension::readIptcTags in Exif 8

Same name and namespace in other branches
  1. 8.2 src/ExifPHPExtension.php \Drupal\exif\ExifPHPExtension::readIptcTags()
  2. 7 ExifPHPExtension.php \Drupal\exif\ExifPHPExtension::readIPTCTags()

Read IPTC 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::readIptcTags()
ExifPHPExtension::readMetadataTags in src/ExifPHPExtension.php
Read all metadata tags.

File

src/ExifPHPExtension.php, line 214

Class

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

Namespace

Drupal\exif

Code

private function readIptcTags($file, $enable_sections) {
  $humanReadableKey = $this
    ->getHumanReadableIptcDescriptions();
  $infoImage = [];
  getimagesize($file, $infoImage);
  $iptc = empty($infoImage["APP13"]) ? [] : iptcparse($infoImage["APP13"]);
  $arSmallIPTC = [];
  if (is_array($iptc)) {
    if (array_key_exists(ExifPHPExtension::IPTC_KEYWORD_KEY, $iptc)) {
      $iptc[ExifPHPExtension::IPTC_KEYWORD_KEY] = $this
        ->checkKeywordString($iptc[ExifPHPExtension::IPTC_KEYWORD_KEY]);
      $iptc[ExifPHPExtension::IPTC_KEYWORD_KEY] = $this
        ->removeEmptyIptcKeywords($iptc[ExifPHPExtension::IPTC_KEYWORD_KEY]);
    }
    foreach ($iptc as $key => $value) {
      if (count($value) == 1) {
        $resultTag = $value[0];
      }
      else {
        $resultTag = $value;
      }
      if (array_key_exists($key, $humanReadableKey)) {
        $humanKey = $humanReadableKey[$key];
        $arSmallIPTC[$humanKey] = $resultTag;
      }
      else {
        $arSmallIPTC[$key] = $resultTag;
      }
    }
  }
  if ($enable_sections) {
    return [
      'iptc' => $arSmallIPTC,
    ];
  }
  else {
    return $arSmallIPTC;
  }
}