2017 © Pedro Peláez
 

library phpexiftool

Exiftool driver for PHP

image

phpexiftool/phpexiftool

Exiftool driver for PHP

  • Thursday, March 10, 2016
  • by romain
  • Repository
  • 14 Watchers
  • 104 Stars
  • 52,210 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 22 Forks
  • 19 Open issues
  • 8 Versions
  • 1 % Grown

The README.md

PHP-Exiftool

Build Status, (*1)

PHP Exiftool is an Object Oriented driver for Phil Harvey's Exiftool (see http://www.sno.phy.queensu.ca/~phil/exiftool/). Exiftool is a powerfull library and command line utility for reading, writing and editing meta information written in Perl., (*2)

PHPExiftool provides an intuitive object oriented interface to read and write metadatas., (*3)

You will find some example below. This driver is not suitable for production, it is still under heavy development., (*4)

Installation

The recommended way to install PHP-Exiftool is through composer., (*5)

{
    "require": {
        "phpexiftool/phpexiftool": "~0.1.0"
    }
}

Usage

Exiftool Reader

A simple example : how to read a file metadatas :, (*6)

<?php

require __DIR__ . '/vendor/autoload.php';

use Monolog\Logger;
use PHPExiftool\Reader;
use PHPExiftool\Driver\Value\ValueInterface;

$logger = new Logger('exiftool');
$reader = Reader::create($logger);

$metadatas = $reader->files(__FILE__)->first();

foreach ($metadatas as $metadata) {
    if (ValueInterface::TYPE_BINARY === $metadata->getValue()->getType()) {
        echo sprintf("\t--> Field %s has binary datas" . PHP_EOL, $metadata->getTag());
    } else {
        echo sprintf("\t--> Field %s has value(s) %s" . PHP_EOL, $metadata->getTag(), $metadata->getValue()->asString());
    }
}

An example with directory inspection :, (*7)

use Monolog\Logger;
use PHPExiftool\Reader;
use PHPExiftool\Driver\Value\ValueInterface;

$logger = new Logger('exiftool');
$Reader = Reader::create($logger);

$Reader
  ->in(array('documents', '/Picture'))
  ->extensions(array('doc', 'jpg', 'cr2', 'dng'))
  ->exclude(array('test', 'tmp'))
  ->followSymLinks();

foreach ($Reader as $MetaDatas) {
    echo "found file " . $MetaDatas->getFile() . "\n";

    foreach ($MetaDatas as $metadata) {
        if (ValueInterface::TYPE_BINARY === $metadata->getValue()->getType()) {
            echo sprintf("\t--> Field %s has binary datas" . PHP_EOL, $metadata->getTag());
        } else {
            echo sprintf("\t--> Field %s has value(s) %s" . PHP_EOL, $metadata->getTag(), $metadata->getValue()->asString());
        }
    }
}

Exiftool Writer

<?php

require __DIR__ . '/vendor/autoload.php';

use Monolog\Logger;
use PHPExiftool\Writer;
use PHPExiftool\Driver\Metadata\Metadata;
use PHPExiftool\Driver\Metadata\MetadataBag;
use PHPExiftool\Driver\Tag\IPTC\ObjectName;
use PHPExiftool\Driver\Value\Mono;

$logger = new Logger('exiftool');
$Writer = Writer::create($logger);

$bag = new MetadataBag();
$bag->add(new Metadata(new ObjectName(), new Mono('Pretty cool subject')));

$Writer->write('image.jpg', $bag);

License

Project licensed under the MIT License, (*8)

The Versions