The PHP JPEG Metadata Toolkit - Documentation

Go to Documentation - Examples

Example Metadata Display Script

This example script is included with the PHP JPEG Metadata Toolkit. It shows how the library can be used to display detailed metadata from a JPEG image file. This is an explanation of some of the commands used in the script.

Click here to see the script



Error Reporting

Although this library has been tested to be error free on a large number of images, it is good programming to turn error reporting off, to ensure that users don't see any error messages. This is not just cosmetic, it helps hide the details of the program from hackers.

        // Turn off Error Reporting
        error_reporting ( 0 );
                

Includes

Ensure that the correct files are included:

JPEG.php For accessing basic JPEG functions - most programs will need this
EXIF.php For accessing Exchangeable Image File Format (EXIF) APP1 segments
JFIF.php For accessing JPEG File Interchange Format and JFIF Extension segments
Photoshop_IRB.php For accessing Photoshop IRB & IPTC-NAA IIM segments
PictureInfo.php For accessing APP12 Picture Info segments
XMP.php For accessing APP1 XMP / RDF / Dublin Core segments


Displaying Metadata Information

Displaying metadata in HTML format from a PHP script is very simple. For example, the following will display any EXIF information in a JPEG image:

        echo Interpret_EXIF_to_HTML( get_EXIF_JPEG( $filename ), $filename );
                


To display the Photoshop IRB and IPTC-NAA information, use:

        echo Interpret_IRB_to_HTML( get_Photoshop_IRB( get_jpeg_header_data( $filename ) ), $filename );
                


Note: The HTML returned from these functions is just a fragment, and requires <HTML>, <HEAD> and <BODY> tags to be provided.



Writing Metadata Information

Although this is not shown in the example script, writing metadata is also very simple. For example, the following will allow the EXIF data in an image to be modified, and written to a file called "output.jpg" :

        $exif_data = get_EXIF_JPEG( $filename );

        // Modify the $exif_data array here

        $jpeg_header_data = put_EXIF_JPEG( $exif_data, $jpeg_header_data );
        put_jpeg_header_data( $filename, "output.jpg", $jpeg_header_data );