射手座X/beluga.drawing.image.exif

一些易于获取图像EXIF和IPTC元数据的工具

0.1.0 2016-08-25 10:55 UTC

This package is not auto-updated.

Last update: 2024-09-12 01:42:15 UTC


README

一些易于获取图像EXIF和IPTC元数据的工具

安装

composer require sagittariusx/beluga.drawing.image.exif

或在您的composer.json中包含它

{
   "require": {
      "sagittariusx/beluga.drawing.image.exif": "^0.1.0"
   }
}

用法

如果您想从图像中加载一些EXIF和/或IPTC数据,您可以通过以下4种方式之一完成

仅使用PHP

// Init the PHP only loader that get the data directly without requirement of some PHP extensions or something else
$loader = new \Beluga\Drawing\Image\Exif\Loader\PHP();

// Load the META data from a image
$data = $loader->load( __DIR__ . '/IMG_0169-2.JPG' );

// Debug output the META data
print_r( $data );

使用ExifTool

如果您已安装ExifTool(适用于Win、MAC和Linux)命令行实用程序,您可以使用它来获取更详细的META数据。

// Init the loader
$loader = new \Beluga\Drawing\Image\Exif\Loader\ExifTool();

if ( ! $loader->isConfigured() )
{
   // Exiftool is not known to the system, declare it manually
   try
   {
      $loader->configure( [ 'path' => '\usr\local\bin\exiftool' ] );
   }
   catch ( \Throwable $ex ) { echo $ex; exit; }
}

if ( ! $loader->isConfigured() )
{
   // The loader for exiftool is not configured right
   // Use the PHP loader as fallback. It will always do the job
   $loader = new \Beluga\Drawing\Image\Exif\Loader\PHP();
}


// Load the META data from a image
$data = $loader->load( __DIR__ . '/IMG_0169-2.JPG' );

// Debug output the META data
print_r( $data );

使用ExiV2

它与exiftool相同,但使用exiv2可执行文件。

使用JSON侧车文件

如果图像具有带有JSON格式的侧车文件,该文件声明了图像META数据,则这种加载是正确的。

如果图像的名称例如为foo.jpg,则将使用侧车文件foo.jpg.jsonfoo.json

// Init the JSon sidecar files loader
$loader = new \Beluga\Drawing\Image\Exif\Loader\JSon();

// Load the META data from a image
$data = $loader->load( __DIR__ . '/IMG_0169-2.JPG' );

// Debug output the META data
print_r( $data );