PHPackages                             diderich/metadata - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. diderich/metadata

ActiveLibrary[Image &amp; Media](/categories/media)

diderich/metadata
=================

HOLIDAY - Metadata / PHP classes for reading and writing metadata from/to JPEG files

v1.1.1(3y ago)81291MITPHPPHP &gt;=8.0

Since Jul 10Pushed 3y ago2 watchersCompare

[ Source](https://github.com/diderich/metadata)[ Packagist](https://packagist.org/packages/diderich/metadata)[ RSS](/packages/diderich-metadata/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)DependenciesVersions (6)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/c526969ad145ca30d8e02a322501b7e39ec904832b883a3bf6bc6b50652a3ac8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64696465726963682f6d65746164617461)](https://packagist.org/packages/diderich/metadata)[![Minimum PHP version](https://camo.githubusercontent.com/b03dc6c9bf997b63cfb030a32d27b0e3ad58de09e435deca0dc266373b596367/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f64696465726963682f6d65746164617461)](https://packagist.org/packages/diderich/metadata)[![License: MIT](https://camo.githubusercontent.com/0d72c4cb15193b9e2e0f21dfc6ce0c8a1f49edd2719e2f9550808afd5e329576/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c756576696f6c65742e737667)](https://github.com/diderich/metadata/blob/master/LICENSE)[![Standard](https://camo.githubusercontent.com/f658270c7498c06a67275b029d214704cb299488b64952f94e72dfc348b5f3ba/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7374616e646172642d4950544325323050686f746f2532304d657461646174612532305374616e64617264253230323032312e312d79656c6c6f77)](https://iptc.org/standards/photo-metadata/interoperability-tests/)[![PHP Innovation Award](https://camo.githubusercontent.com/f31cde36be1ef4169f9f1b415948661171527c7a4b048c3f4314229e37acb4fd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850253230496e6e6f766174696f6e25323041776172642d57696e6e65722d677265656e)](https://www.phpclasses.org/package/12584-PHP-Read-and-write-metadata-stored-in-JPEG-image-files.html)

Name
====

[](#name)

**Metadata** - A PHP class for reading and writing *Photo Metadata* from JPEG files in a transparent way

Version
=======

[](#version)

See `CHANGELOG.md` and php constant `\Holiday\Metadata::VERSION` for the latest version number.

Awards
======

[](#awards)

[![PHP Innovation Award](https://camo.githubusercontent.com/fe57c4c057a2f4deeaef9ea59463ccb88f4fa362499336ac31c5a14bec4681a2/68747470733a2f2f66696c65732e706870636c61737365732e6f72672f67726170686963732f706870636c61737365732f696e6e6f766174696f6e2d61776172642d6c6f676f2e706e67)](https://www.phpclasses.org/package/12584-PHP-Read-and-write-metadata-stored-in-JPEG-image-files.html)

Description
===========

[](#description)

The **Metadata** class and its sub-classes implement transparent read and write access to IPTC Photo Metadata based on the *IPTC Photo Metadata Standard 2021.1* and read access to EXIF data from JPEG files, focusing on those metadata elements that are relevant for searching and managing photos within a photo database or similar application. The class is unique in the sense that it supports multiple concurrent languages for the caption/description information.

There exist many implementations for reading and/or writing metadata from photos of various formats. Typically, these packages and programs (`exiftool` being the most prominent one) focus on decoding raw data in the context of its origin, e.g., decoding EXIF data or decoding IPTC/APP13 data. This project takes a different approach! It takes a user-centric approach and exposes IPTC and EXIF photo metadata in a transparent way to the user, i.e, the user does not have to worry where the data is coming from and/or how it is encoded.

The package has been developed in the context of the proprietary HOLIDAY photo database software (see ) as the end-user. As such it may lack functionality relevant for different uses. This explains also the use of the top-level namespace prefix `\Holiday`.

The decoding and encoding of the JPEG image file into different header segments as well as the decoding and encoding of the IPTC data is inspired in part by **The PHP JPEG Metadata Toolkit** (), which is hereby duly acknowledged.

Transparent access to JPEG image metadata
-----------------------------------------

[](#transparent-access-to-jpeg-image-metadata)

The class `\Holiday\Metadata` allows reading and writing the most relevant (from the author's perspective) photo metadata in JPEG files and access them in a transparent way, independent of where/how they are stored. Data for a field FIELD\_ID can be read from file FILENAME using the following code. If no data is found, `$data` will be equal to `false`, otherwise it will contain the data read, which may be a string, an integer, or an array:

```
$metadata = new \Holiday\Metadata();

$metadata->read(FILENAME);
$data = $metadata->get(\Holiday\Metadata::FIELD_ID);
```

Data in field FIELD\_ID can be updated to NEW\_DATA and written back to the same file or a new different file NEW\_FILENAME using the code:

```
$metadata->set(\Holiday\Metadata::FIELD_ID, NEW_DATA);
$metadata->write(NEW_FILENAME);
```

The file NEW\_FILENAME is automatically overwritten.

Pasting the editable part of the metadata from one file FILENAME to another one named PASTE\_FILENAME (which must exist), can be done using the following code:

```
$metadata = new \Holiday\Metadata();

$metadata->read(FILENAME);
$metadata->paste(PASTE_FILENAME);
```

The caption/description field `\Holiday\Metadata::CAPTION` supports multiple languages, the default language being named according to the standard) `\Holiday\Metadata::LANG_DEFAULT`. Access the field's data is done using the following code:

```
// Retrieve the default data
$caption = $metadata->get(\Holiday\Metadata::CAPTION, lang: \Holiday\Metadata::LANG_DEFAULT);

// Retrieve the data in a specific language, e.g., 'de-de' (German)
$caption = $metadata->get(\Holiday\Metadata::CAPTION, lang: 'de-de');

// Retrieve the data in all available languages (an array, indexed with the respective language identifier is returned)
$caption_ary = $metadata->get(\Holiday\Metadata::CAPTION, lang: \Holiday\Metadata::LANG_ALL);
```

The metadata is read in the following order, the first data read taking priority, i.e, if the CAPTION data is stored in the IPTC/APP13 segment as well as in the XMP/APP1 and EXIF/APP1 segment, the data from the IPTC/APP13 will prevail.

1. Data found in the IPTC/APP13 segment
2. Data found the XMP/APP1 segment
3. Data found in the EXIF/APP1 segment

When writing the metadata back, both IPTC/APP13 and XMP/APP1 fields will be updated to ensure consistency of the data. In the current implementation, user modifiable data stored in the EXIF/APP1 segment is cleared, i.e., replaced by 0x00, rather than updated to the actual value. This choice is due to a) the opinion that EXIF/APP1 should not contain user-editable data and b) the complexity of the EXIF/APP1 data format.

Exception handling
------------------

[](#exception-handling)

All functions return `false`in case of non-fatal errors. Fatal errors trigger the exception `\Holiday\Metadata\Exception` to be thrown (which extends the generic `Exception` class). The numerical code associated with an error (`$exception->getCode()`) allows identifying the type of the error. Constants are defined in the exception class `\Holiday\Metadata\Exception`.

The function `\Holiday\Metadata\Exception::getData()`returns additional data relevant to the thrown exception in human readable form.

All exception messages are translatable using the `gettext` library. A translation template is provided in the `locale`directory.

Example
=======

[](#example)

The following example shows how to read, modify, and write metadata from JPEG files in a transparent way (see also `test/example.php`). Is requires/assumes a PSR-4 compliant mechanism for loading the class files.

```
// Create an instance of the Metadata class
$metadata = new \Holiday\Metadata();

try {
  // Read metadata from the image file FILENAME
  $metadata->read(FILENAME);

  // Read some of the metadata (assuming metadata is available)
  $caption = $metadata->get(\Holiday\Metadata::CAPTION, lang: \Holiday\Metadata::LANG_DEFAULT);
  $caption_ary = $metadata->get(\Holiday\Metadata::CAPTION);
  $date_created = $metadata->get(\Holiday\Metadata::CREATED_DATETIME);
  $credit = $metadata->get(\Holiday\Metadata::CREDIT);
  $city = $metadata->get(\Holiday\Metadata::CITY);
  $country = $metadata->get(\Holiday\Metadata::COUNTRY);
  $people = $metadata->get(\Holiday\Metadata::PEOPLE);
  $keywords = $metadata->get(\Holiday\Metadata::KEYWORDS);
  $event = $metadata->get(\Holiday\Metadata::EVENT);
  if(!empty($caption_ary)) {
    echo "CAPTION:".PHP_EOL;
    foreach($caption_ary as $lang => $text)
      echo "   $lang: $text".PHP:EOL;
  }
  if($credit !== false) echo "CREDIT:   $credit".PHP_EOL;
  if($city !== false && $country !== false) echo "PLACE:    $city, $country".PHP_EOL;
  if($date_created !== false) echo "CREATED:  ".date('d.m.Y', $date_created).PHP_EOL;
  if($event !== false) echo "EVENT:    $event".PHP_EOL;
  if($keywords !== false) echo "KEYWORDS: ".implode(', ', $keywords).PHP_EOL;
  if($people !== false) echo "PEOPLE:   ".implode(', ', $people).PHP_EOL;

  // Update some data
  if($caption !== false && $date_created !== false && $city !== false && $country !== false && $credit !== false) {
    $caption = strtoupper($city).', '.strtoupper($country).' - '.strtoupper(date('F d', $date_created)).': '.
      $caption.' (Photo by '.$credit.')';
    $metadata->set(\Holiday\Metadata::CAPTION, $caption, lang: \Holiday\Metadata::LANG_DEFAULT);
  }
  if($event !== false) $metadata->set(\Holiday\Metadata::EVENT, strtoupper($event));

  // Write metadata back to the image file
  $metadata->write(FILENAME);

  // Paste user modifiable metadata do a different file
  $metadata->paste(ALTERNATE_FILE);
```

File and directory structure
============================

[](#file-and-directory-structure)

The directory structure shown describes the most relevant directories and files of the library.

All class files are commended in a phpDocumenter () compliant way.

```
|-- src/                    Directory containing all class files required to use the library
  |-- Metadata.php          Class implementing transparent read/write access to JPEG metadata
    |-- Metadata
      |-- Exception.php     Exception handling class
      |-- Exif.php          Class reading and writing EXIF/APP1 specific raw data
      |-- Iptc.php          Class reading and writing IPTC/APP13 specific raw data
      |-- Jpeg.php          Class reading and writing JPEG header segment data
      |-- Xmp
	    |-- Document.php    Class encoding and decoding Xmp data in a DOMDocument class format
      |-- Xmp.php           Class reading and writing XMP/APP1 specific data
|-- test/
  |-- example.php           Sample program using the metadata class libraries
  |-- example.txt           Sample program output
  |-- img.example.jpg       Sample image including data in all supported fields
  |-- img.mlexample.jpg     Sample image containing caption data in two languages
|-- locale/
  |-- metadata.pot          Untranslated text messages generated by the classes
|-- README.md
|-- CHANGELOG.md
|-- LICENSE
|-- composer.json

```

Installation
============

[](#installation)

The metadata class can be installed using composer

```
composer require diderich/metadata
```

Testing
=======

[](#testing)

The classes have been successfully tested on a number of JPEG images written by a non-exhaustive list of different camera models. As decoding data is highly dependent on the choices made when encoding the data, the class may be unable to decode some less common JPEG file encodings. This is especially the case for data stored (in a less compliant way) using th XMP format.

No exhaustive test concept for the classes exists and/or is planned.

If you find a JPEG file that is not correctly decoded, please raise an issue in the `Issue` section AND include a copy of the JPEG file. Issus without accompanying JPEG data will be closed by the author without consideration.

Open issues
===========

[](#open-issues)

The following limitations currently exist and are acknowledged as such:

- IPTC/APP13: Only Latin 1 and UTF-8 encoded data can be read. Other data formats will throw an exception.
- XMP/APP1: The classes Xmp and/or Xmp\\Document may nor recognize all poorly/incorrectly formatted XMP/APP1 data.
- XMP/APP1: If a data element TAG is updated in the namespace NS, then it will also be updated in the namespaces Iptc4xmpCore, dc, aux, xmp, photoshop, and photomechanic, if a data entry exists in those name spaces. Other name spaces, for example, used by other applications, are not updated/synchronized. This may result in inconsistent data.
- EXIF/APP1: Although all data read is returned, only the data considered relevant is decoded. For example, thumbnails or markernotes are not decoded. Data not decoded is returned as a human readable hexadecimal string.
- EXIF/APP1: Due to the complexity of writing EXIF/APP1 data, the IPTC/NAA records in the EXIF IFD are not updated. They are overwritten with \\x00. The author is not aiming a removing these limitations in the future.

Important note
==============

[](#important-note)

Files containing caption/description data in more than one language may not be correctly read/saved by most (it not all) photo editing software, like Photoshop. To the author's knowledge, no of-the-shelve software currently supports multiple concurrent languages, as described by the *XMP Specification* (referenced as *Lang Alt*). See  for more details about interoperability.

Support
=======

[](#support)

Free community support is available on `github.com` using the Issues and Discussion sections. The author may participate in providing free support, but does not guarantee to do so. Guaranteed paid support is available from the author.

Project status and road-map
===========================

[](#project-status-and-road-map)

The project is actively maintained. Not new features are currently planned.

Author
======

[](#author)

Claude Diderich (), . The author will respond to e-mails at his own discretion.

License
=======

[](#license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

5

Last Release

1389d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/14a30bcbaf7458649cfe20e115d4daa7d9810eec060f97805244796755bdd678?d=identicon)[diderich](/maintainers/diderich)

---

Top Contributors

[![diderich](https://avatars.githubusercontent.com/u/10230144?v=4)](https://github.com/diderich "diderich (37 commits)")

---

Tags

exifiptcjpegjpgmetadataxmpimagemetadatajpegexifxmp

### Embed Badge

![Health badge](/badges/diderich-metadata/health.svg)

```
[![Health](https://phpackages.com/badges/diderich-metadata/health.svg)](https://phpackages.com/packages/diderich-metadata)
```

###  Alternatives

[frameright/image-metadata-parser

Image metadata parsing library

1133.9k](/packages/frameright-image-metadata-parser)[fileeye/pel

PHP Exif Library. A library for reading and writing Exif headers in JPEG and TIFF images using PHP.

197.1M2](/packages/fileeye-pel)[joserick/png-metadata

A PHP library for extract the metadata (XMP, EXIF) within a PNG format image.

2234.7k](/packages/joserick-png-metadata)[lychee-org/php-exif

Object-Oriented EXIF parsing

1085.0k1](/packages/lychee-org-php-exif)[carlcs/craft-assetmetadata

Asset Metadata plugin for Craft CMS

316.8k](/packages/carlcs-craft-assetmetadata)[jellybellydev/image-orientation-fix

PHP library to fix image orientation by exif data.

1810.8k](/packages/jellybellydev-image-orientation-fix)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
