You are here

function _exif_read_exif in Exif 5

Reads exif data from a file.

1 call to _exif_read_exif()
_update_exif_data in ./exif.module
Update exif data for a given file.

File

./exif.module, line 140

Code

function _exif_read_exif($file) {
  _exif_bootstrap();
  $data = array();
  if (!file_exists($file)) {
    watchdog('exif', t('Image %file not found.', array(
      '%file' => $file,
    )), WATCHDOG_WARNING);
    return $exif;
  }
  if (exif_imagetype($file) != IMAGETYPE_JPEG) {
    return $data;
  }
  $jpeg = new PelJpeg($file);
  $exif = $jpeg
    ->getExif();
  if (!$exif) {
    return $data;
  }
  $tiff = $exif
    ->getTiff();
  if (!$tiff) {
    return $data;
  }
  $ifd0 = $tiff
    ->getIfd();
  if (!$ifd0) {
    return $data;
  }
  $ifds[PelIfd::IFD0] = $ifd0;
  if ($exif = $ifd0
    ->getSubIfd(PelIfd::EXIF)) {
    $ifds[PelIfd::EXIF] = $exif;
  }
  if ($gps = $ifd0
    ->getSubIfd(PelIfd::GPS)) {
    $ifds[PelIfd::GPS] = $gps;
  }
  $tags = exif_get_enabled_tags();
  $data = array();
  foreach ($tags as $tag) {
    $entry = $ifds[$tag->ifd]
      ->getEntry($tag->tag);
    if ($entry) {
      $row = array();
      switch ($tag->tag) {
        case PelTag::DATE_TIME:
        case PelTag::DATE_TIME_ORIGINAL:
        case PelTag::DATE_TIME_DIGITIZED:

          // Return a unixtimestamp. Theme will handle date formating.
          $data[$tag->ifd][$tag->tag] = $entry
            ->getValue();
          break;
        default:
          $data[$tag->ifd][$tag->tag] = utf8_encode($entry
            ->getText());
      }
    }
  }
  return $data;
}