如何从图像元数据PHP获取标签?

时间:2018-10-28 11:35:13

标签: php tags metadata

我正在尝试从图像元数据中获取标签。我使用以下函数来获取元数据,但标签位于数组中。我不知道如何打印所有标签。

功能:

IMessage

那是exif_read_data的输出: enter image description here 我尝试过:

<?php
function cameraUsed($imagePath) {
    if ((isset($imagePath)) and (file_exists($imagePath))) {
      $exif_ifd0 = read_exif_data($imagePath ,'IFD0' ,0);       
      $exif_exif = read_exif_data($imagePath ,'EXIF' ,0);
      $notFound = "Unavailable";
      if (@array_key_exists('Make', $exif_ifd0)) {
        $camMake = $exif_ifd0['Make'];
      } else { $camMake = $notFound; }
      if (@array_key_exists('Model', $exif_ifd0)) {
        $camModel = $exif_ifd0['Model'];
      } else { $camModel = $notFound; }
      if (@array_key_exists('ExposureTime', $exif_ifd0)) {
        $camExposure = $exif_ifd0['ExposureTime'];
      } else { $camExposure = $notFound; }
      if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED'])) {
        $camAperture = $exif_ifd0['COMPUTED']['ApertureFNumber'];
      } else { $camAperture = $notFound; }
      if (@array_key_exists('DateTime', $exif_ifd0)) {
        $camDate = $exif_ifd0['DateTime'];
      } else { $camDate = $notFound; }
      if (@array_key_exists('ISOSpeedRatings',$exif_exif)) {
        $camIso = $exif_exif['ISOSpeedRatings'];
      } else { $camIso = $notFound; }     
      if (@array_key_exists('UndefinedTag:0xA434',$exif_exif)) {
        $test = $exif_exif['UndefinedTag:0xA434'];
      } else { $test = $notFound; }     

      if (@array_key_exists('UndefinedTag:0xA434',$exif_exif)) {
        $test = $exif_exif['UndefinedTag:0xA434'];
      } else { $test = $notFound; }

      if (@array_key_exists('UndefinedTag:0xA432',$exif_exif)) {
        $tags = $exif_exif['UndefinedTag:0xA432'];
      } else { $tags = $notFound; }

      $return = array();
      $return['make'] = $camMake;
      $return['model'] = $camModel;
      $return['exposure'] = $camExposure;
      $return['aperture'] = $camAperture;
      $return['date'] = $camDate;
      $return['iso'] = $camIso;
      $return['tags'] = $tags;
      return $return;

    } else {
      return false; 
    } 
}

?>

但是当尝试打印时,什么也没有。

1 个答案:

答案 0 :(得分:0)

您可以免费使用http://image.intervention.io/中的库,并从中获得图像的exif数据。

// read all existing data into an array
$data = Image::make('public/foo.jpg')->exif();

// read model of the camera
$name = Image::make('public/foo.jpg')->exif('Model');

希望它对您有帮助:)