Git Product home page Git Product logo

phpexiftool's Introduction

PHP-Exiftool

Build Status

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.

PHPExiftool provides an intuitive object oriented interface to read and write metadatas.

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

Installation

The recommended way to install PHP-Exiftool is through composer.

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

Usage

Exiftool Reader

A simple example : how to read a file metadatas :

<?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 :

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

phpexiftool's People

Contributors

cedcannes avatar michalsanger avatar nlegoff avatar nousefreak avatar romainneutron avatar simonsimcity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpexiftool's Issues

Can't write proper IDF0:Orintation tag value

When I try to copy tags from one file to another I found, that setting orientation tag is working not proper way (or I used it wrong).

$logger = new Logger('exiftool');
$reader = Reader::create($logger);
$Writer = Writer::create($logger);
$bag = new MetadataBag();
$metadatas = $reader->files($file)->first();
foreach ($metadatas as $metadata) {
     if(strpos(get_class($metadata->getTag()), 'Orientation')!==false)
     {
          $bag->add($metadata);
     }
}
$Writer->write($file, $bag);

This generating code:
exiftool -IFD0:Orientation='1' -overwrite_original_in_place some.jpg -common_args -preserve -charset UTF8 -codedcharacterset=utf8
And after executing it, I have IFD0:Orientation = 3.

But for using int values on orientation FAQ says to set -n attribute or suffixing tag with # (-IFD0:Orientation#='1')

writing exif data does not work

I am trying to add a copyright notice to photos using your package but unfortunately it does not seem to work, when running the "exif" command on the processed image file I get:

Corrupt data
The data provided does not follow the specification.
ExifLoader: The data supplied does not seem to contain EXIF data.

If I open the JPG image in GIMP it doesn't show many anything under the copyright tab of the image properties.

I use the following code which is pretty much the same as in your README:

            $logger = new Logger('exiftool');
            $Writer = Writer::create($logger);
            $bag = new MetadataBag();
            $bag->add(new Metadata(new CopyrightNotice(), new Mono('Test copyright notice')));
            $Writer->write($filteredFilename, $bag);

and use v0.3 of the package. Any ideas?

PHP simple example

Hi,
Im trying to use this library but I couldnt find any simple easy to understand example on how to add and use this library.
I want to create a page that allow a user to see and edit the metadata of a jpeg file and save the new metadata to the same file.
Any help here?

writer not working

Using PHP 7.0.10 and PHP 5.6.25 - I used the example from the README.md file did not error, but did not write any new tags. When I print_r($bag), I received this:
Doctrine\Common\Collections\ArrayCollection@0000000036737d36000000005f314cfe
print_r($Writer) produced nothing.

What's the difference between SupportorAdministrationStatus and SupportOrAdministrationStatus?

I discovered a tag, that exists once as SupportorAdministrationStatus and another time as SupportOrAdministrationStatus class.

Those classes have different settings but the same name if you have a system, that doesn't support case-sensitive filenames.

Will this work on a Windows machine the way it works on a linux machine, where you can use a case-sensitive file-system?

You can see the differences between a case-sensitive and a case-insensitive file-system in this chageset:
https://github.com/SimonSimCity/PHPExiftool/commit/e7654689648a1edc75b5273c1999e108b571188f

Wrong way of importing classes

Hello.

In the file TagFactory, you are using this method :
protected static function classnameFromTagname($tagname)

It's using datas coming from EXIF to generate the classname you are looking for. Here CreatorTool.

The issue is that in a picture I have, this CreatorTool is written Creatontool.(without the second uppercase on Tool).
Consequence, your software is looking for Creatortool class, which doesn't exist.

leading to this error.

Case mismatch between loaded and declared class names: PHPExiftool\Driver\Tag\XMPXmp\Creatortool vs PHPExiftool\Driver\Tag\XMPXmp\CreatorTool 

On windows, I cannot create a second file with no uppercase, the system find them as identical.
(not case sensitive)

I see 2 ways of resolving this issue :

  • to put all tagname in uppercase and to rename the class using the same way.(or to put everything lowercase except the first character, your choice)
  • to change this method to check if the file exist, and if not to look for similar file / class (no idea on how to do this one)

What is your feedback ?

Best regards,
Pierre

setMode(...) method does not work properly

from @jygaulier see (alchemy-fr/exiftool#2)

setMode(...) adds -@... AFTER the common_args
step to reproduce / explain : see sample code

<?php
use PHPExiftool\Exiftool;
use PHPExiftool\Writer;
use PHPExiftool\Driver\Metadata;
use PHPExiftool\Driver\Value;
use PHPExiftool\Driver\Tag;
use Psr\Log\NullLogger;

require_once __DIR__ . '/../lib/autoload.php';

//Exiftool calls "addinfo" wich is not in LoggerInterface ?

class myNullLogger extends NullLogger
{
    public function addInfo($s)
    {
        echo $s . "\n";
    }
}

$writer = new Writer( new Exiftool(new myNullLogger()));

$writer->erase(true, false);     // erase everything

$writer->setMode(Writer::MODE_IPTC2XMP, true);

// because of MODE_IPTC2XMP, IPTC:ObjectName should be copied in XMP-dc:Title
$metadatas = new Metadata\MetadataBag();
$metadatas->add(
    new Metadata\Metadata(
        new Tag\IPTC\ObjectName(),
        new Value\Mono("--Object--")
    )
);

$writer->write("test.jpg", $metadatas);

This command does not work because 2 commands appears after the common args

exiftool -all:all= test.jpg -execute  -IPTC:ObjectName='--Object--' -overwrite_original_in_place test.jpg -common_args -preserve -charset UTF8 -codedcharacterset=utf8 -overwrite_original_in_place -execute -overwrite_original_in_place  -@ ../vendor/phpexiftool/exiftool/iptc2xmp.args test.jpg

Ignoring -common_args from -execute onwards to avoid infinite recursion
    1 image files updated
Ignoring -common_args from -execute onwards to avoid infinite recursion
    1 image files updated

This command works because all the common args are LAST args
nb: EVEN THE FILENAME can be pushed into common args !

exiftool -all:all= -execute -IPTC:ObjectName='--Object--' -execute -@ ../vendor/phpexiftool/exiftool/iptc2xmp.args -common_args -preserve -charset UTF8 -codedcharacterset=utf8 -overwrite_original_in_place test.jpg
    1 image files updated
    1 image files updated
    1 image files updated

error proc_open

Hello,

I'm getting the following error when I try to read the file.
It seems that it cannot create a new process.
Do you have any idea why ?

Why to not use a simple exec call ? what's the gain of proc_open ?

Warning: proc_open(): CreateProcess failed, error code - 2 in C:\My Program Files\xampp\htdocs\exif\vendor\symfony\symfony\src\Symfony\Component\Process\Process.php line 280 

Best regards,
Thank you.

PHPExiftool is incompatible with latest Symfony versions

I want to use the tool in a Symfony 2.8.9 project but when I execute composer update I get this error:

Problem 1
- Installation request for phpexiftool/phpexiftool ~0.1.0 -> satisfiable by phpexiftool/phpexiftool[0.1.0].
- Conclusion: remove symfony/symfony v2.8.9

Missing base64_decode on PDF-Keyword-Reading (AppleKeywords)

When having a PDF with Keywords added by apple there are some mistakes happening. Especially when non ASCI-Chars are involved. I added a Test.pdf to demonstrate this.

There are three "normal" keywords labled Test1, Test2, and Test3. A fourth keyword is a bit more complex. It contains a comma (!) and some german umlaute: Base64 encoded äöü and comma, foo bar.

This is the exiftool XML-Output of the Keywords and AppkeKeywords section:

<PDF:Keywords>
  <rdf:Bag>
   <rdf:li>Test1</rdf:li>
   <rdf:li>Test2</rdf:li>
   <rdf:li>Base64 encoded äöü and comma</rdf:li>
   <rdf:li>foo bar</rdf:li>
   <rdf:li>Test3</rdf:li>
  </rdf:Bag>
 </PDF:Keywords>
 <PDF:AppleKeywords>
  <rdf:Bag>
   <rdf:li>Test1</rdf:li>
   <rdf:li>Test2</rdf:li>
   <rdf:li rdf:datatype='http://www.w3.org/2001/XMLSchema#base64Binary'>
/v8AQgBhAHMAZQA2ADQAIABlAG4AYwBvAGQAZQBkACAA5AD2APwAIABhAG4A
ZAAgAGMAbwBtAG0AYQAsACAAZgBvAG8AIABiAGEAcg==
</rdf:li>
   <rdf:li>Test3</rdf:li>
  </rdf:Bag>
 </PDF:AppleKeywords>

As you can see there are two problems infolved:

  1. in the "PDF:Keywords" section the comma IN THE KEYWORD ITSELF is recognized and split to two separat Keywords. Well. That is a Exiftool problem and not part of this issue
  2. The "PDF:AppleKeywords is recognized correctly. But it base64 encodes the umlaute. Up to here everything is fine. The issue though is, that PHPExiftool does not decode the String and returns the ugly string.
    Instead I would expect, that PHPExiftool recognizes the Attribute rdf:datatype='http://www.w3.org/2001/XMLSchema#base64Binary' and automatically decodes the string.

If I have seen this right, this behaviour is already implemented for Mono-Types (see source). But I guess it needs to be also implemented for Multi-Types.

This is the Testfile, mentioned: Test.pdf

Writer example is broken

Copy&paste from readme.md and I get:

PHP Catchable fatal error:  Argument 1 passed to PHPExiftool\Writer::create() must be an instance of Psr\Log\LoggerInterface, none given

How about a single image file

Hello,
I toke the example code but I couldn`t figure out how to pass a single image file to read?
How do I pass an image that set in the same directory of the index.php (which contain the example code)? how do I pass a single image that set in different directory?

Incompatibilities with php 7.0

PHP 7.0 has problem with PHPExiftool\Driver\Tag\EXE\LanguageCode. Seems like it can't parse the value because it interprets it as Octal.

$ php70 -l vendor/phpexiftool/phpexiftool/lib/PHPExiftool/Driver/Tag/EXE/LanguageCode.php
PHP Parse error:  Invalid numeric literal in vendor/phpexiftool/phpexiftool/lib/PHPExiftool/Driver/Tag/EXE/LanguageCode.php on line 80

Parse error: Invalid numeric literal in vendor/phpexiftool/phpexiftool/lib/PHPExiftool/Driver/Tag/EXE/LanguageCode.php on line 80
Errors parsing vendor/phpexiftool/phpexiftool/lib/PHPExiftool/Driver/Tag/EXE/LanguageCode.php

And there are 3 Types that use reserved names in PHP, Float, Null and String, in namespace PHPExiftool\Driver\Type.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.