cnlpete/image-metadata-parser

Exif、ITPC 和 XMP 的抽象

v0.0.6 2014-11-18 11:12 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:55:47 UTC


README

嗨!Image-Metadata-Parser 是一组php函数,旨在简化对某些图像文件元数据(如exif、itpc或xmp)的访问。

用法

要使用 Image-Metadata-Parser,您只需将类放置在您的应用程序中可访问的位置。

然后,您可以使用一些图像文件创建一个新的 ParserObject 并读取其元数据。

<?php
include('inc/imageMetadataParser.php');

$imageparser = new ImageMetadataParser('path/to/imagefile.jpg');
if (!$imageparser->parseExif())
  echo "Parsing of Exif Data failed";
if (!$imageparser->parseIPTC())
  echo "Parsing of IPTC failed";

获取标题

if ($imageparser->hasTitle())
  echo "Image Title: " . $imageparser->getTitle();

获取日期和时间

if ($imageparser->hasDateTime())
  echo "Image Taken At: " . date('r', $imageparser->getDateTime());

获取缩略图

if ($imageparser->hasThumbnail()) {
  echo "<img src='data:" . 
      $imageparser->getThumbnailContentType() .
      ";base64," .
      base64_encode( $imageparser->getThumbnail() ) .
      "' />";
}

检查方向

if ($imageparser->hasOrientation())
  if ($imageparser->getOrientation() === 0)
    echo "Image is oriented properly.<br />\n";
  else
    echo "Image needs to be rotated with imagerotate(image, " . $imageparser->getOrientation() . ", 0);<br />\n";

获取GPS坐标

if ($imageparser->hasGPS()) {
  $dLat = 0; $dLong = 0;
  $imageparser->getGPS($dLat, $dLong);
  echo "approximate GPS position: " .
      "<a href='https://maps.google.com/maps?q=" . $dLat . "," . $dLong . "'>Lat: " . $dLat . " Long: " . $dLong . "</a>";
}

希望您觉得它很有用! :)