XMP4PHP

arrow_up

Introduction

The XMP4PHP extension for PHP offers an interface that can be used to read XMP (Extensible Metadata Platform) meta data from and write meta data to (binary) files. The extension is based on the library exempi , that itself is based on the XMP Toolkit from Adobe .

In its first version the library only allows writing and reading of meta data, but not modifying it. For modifications the DOM functions offered by PHP can be used. In later versions the modification of meta data should be possible by making use of additional functions offered by the XMP Toolkits.

The current version of XMP4PHP is available on the central download page.

arrow_up

Documentation

The functions offered by the extension are shortly described below.

xmp_read( $filename, $openMask = 5, $serializeMask = 1, $encodingMask = 0 )

The function xmp_read expects the name of a file from which the meta data should be read as the first argument. As a result it return the meta data in form of RDF (XML). In case of any error it returns a value lower than one. Those values are summarized in the following table.

Return value

Description

false The parameters passed to the function are not correct.
-1 The exempi library could not be initialzed correctly.
-2 The file could not be opened for reading.
-3 The file does not contain any meta data
-4 There is not enough memory to store the meta data.
-5 The exempi library was not able to serialize the meta data correctly.
-6 The serialized meta data could not be converted into a string.

The other parameters of this function are optional and they expect a bitmask according to the tables at the end of this page.

xmp_write( $filename, $xmlData, $openMask = 5, $serializeMask = 1, $encodingMask = 0 )

The function xmp_write expects the name of a file into which the meta data should be written as well as the meta data itself in form of RDF (XML). It is important to know that the meta data must not contain any information about the XML-Version. If the meta data has been written correctly, the function returns true. In case of any error it returns a value lower than one. Those values are summarized in the following table.

Return value

Description

false The parameters passed to the function are not correct.
-1 The exempi library could not be initialzed correctly.
-2 The passed XML data could no the interpreted / parsed.
-3 The file could not be opened for writing.
-4 The exempi library does not support to write meta data to this file type.

xmp_can_write( $filename, $xmlData, $openMask = 5, $serializeMask = 1, $encodingMask = 0 )

The function xmp_can_write expects the name of a file to verify if the meta data, that is passed with the second parameter, can be written into the file. It is important to know that the meta data must not contain any information about the XML-Version. If the meta data could be written to the file according to the bit masks passed as the optional parameters, the function returns true. In case of any error it returns a value lower than one. Those values are summarized in the following table.

Return value

Description

false Die Übergabe der Parameter war nicht korrekt.
false The parameters passed to the function are not correct.
-1 The exempi library could not be initialzed correctly.
-2 The passed XML data could no the interpreted / parsed.
-3 The file could not be opened for writing.
Possible $openMask values

Value

Description

0 No special options.
1 Open for reading.
2 Open for reading and writing.
4 Only access the XMP content of the file.
8 Unknown.
16 Strict checking.
32 Use intelligent handler.
64 Scan XMP pakets.
128 Limit the amount of scanned XMP pakets.
256 Open in background.
Possible$serializeMaskvalues

Value

Description

1 Do not use paket wrapper.
2 Paket is read only.
4 Use compact format.
8 Use preview area.
16 Exact paket length.
32 Write alias comments.
64 Do not use any formatting.
Possible$encodingMaskvalues

Value

Description

0 UTF-8
1 UTF-16 big endian
2 UTF-16 little endian
4 UTF-32 big endian
8 UTF-32 little endian
arrow_up

Known problems

While testing the exempi library and the XMP Toolkit from Adobe in version 4.1.1 I figured out the following problems.

  • The XMP Toolkit makes use of exception handling to catch critical errors. But some of the functions to not modify the return value if an exception occured. This means that for example the return value of a writing operation is true even if the meta data has not been written to the file because exception occured. Neither XMP4PHP nor exempi are able to influence this behaviour.
  • In exempi version 1.99.4 it is possible that the problem described above can cause a crash of PHP. It seems that this problem does not occur in exempi version 1.99.5 anymore, resulting in a recommendation to make use of the latest version.
eZ Publish™ copyright © 1999-2008 eZ Systems AS