PHP code example of codewiser / exiftool

1. Go to this page and download the library: Download codewiser/exiftool library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codewiser / exiftool example snippets


use Codewiser\Exiftool\Exiftool;

// With latest specification
$exiftool = new Exiftool('/bin/exiftool');

// Or with another
$exiftool = new Exiftool('/bin/exiftool', '/path/to/specification.json');

use Codewiser\Exiftool\Iptc;

public function read(string $filename): Iptc
{
    return $this->exiftool()->read($filenme);
}

use Codewiser\Exiftool\Iptc;
use Symfony\Component\Process\Process;

public function write(string $filename, Iptc $data): Process
{
    return $this->exiftool()->write($filenme, $data);
}

use Symfony\Component\Process\Process;

public function write(string $filename): Process
{
    return $this->exiftool()->clear($filenme, $data);
}

// empty collection
$empty = $exiftool->newMetadata();

// 

$json = $data->jsonSerialize();

$data->fromJson(['captionWriter' => 'me']);

(string) $data->captionWriter;
// the same as
$data->captionWriter?->toString();

$data->captionWriter = 'me';

(string) $data->dateCreated;
// the same as
$data->dateCreated?->toDateTime()->format('c');

$data->dateCreated = time();
$data->dateCreated = new \DateTime();

use Codewiser\Exiftool\Attributes\AltLangAttribute;

AltLangAttribute::useLocale('de');

(string) $data->description;
// the same as
$data->description?->toString();

$data->description = 'about';

$data->description?->toArray();

isset($data->description['cn']);

$data->description['en'] = 'about';

use Codewiser\Exiftool\Attributes\AltLangAttribute;

AltLangAttribute::collapse();

return json_encode($data->jsonSerialized());

$data->creatorContactInfo?->address?->toString();

$data->locationCreated?->name['en']

$data->locationCreated = ['city' => 'London', 'country' => 'UK'];

$data->locationCreated = $exiftool->newStructure()->location();
$data->locationCreated->city = 'London';

foreach ($data->keywords as $keyword) {
    //
}

count($data->keywords);

(string) $data->keywords[0];

$data->keywords = ['value 1', 'value 2'];

// etc.

$data->locationsShown = [
    ['city' => 'London', 'country' => 'UK'],
    ['city' => 'Paris', 'country' => 'France'],
];

use Codewiser\Exiftool\Exiftool;

$exiftool = new Exiftool($bin);

$values = $exiftool->specification()->topLevel()
    ->getAttributeByJsonName('dataMining')->enum();

[
    'MR-NON' => 'None',
    'MR-NAP' => 'Not Applicable',
    'MR-UMR' => 'Unlimited Model Releases',
    'MR-LMR' => 'Limited or Incomplete Model Releases',
]