Hướng dẫn php iptc

Introduction

The PHP JPEG Metadata Toolkit is a library of functions which allows manipulation of many types of metadata that reside in a JPEG image file.

The metadata that can be accessed by this library include:

Metadata Type NameContents
EXIF, DCF & TIFF/EP - including makernotes Contains Digital Camera Settings. Can contain a thumbnail.
XMP, RDF & Dublin Core, including multiple language support Can contain Digital camera settings and text headings/captions.
Photoshop IRB & IPTC-NAA IIM Contains Photoshop settings and can contain text headings/captions. Can contain a thumbnail.
Picture Info Contains Digital Camera Settings for older cameras
JFIF & JFIF Extension Contains limited info about the image and can contain a thumbnail
Intrinsic JPEG Values Contains limited info configuration of the image

Other features

Has been tested with over 450 popular digital cameras Provides access to lots of metadata for which php has no built in support Works with many files that have corrupted metadata. Customisable look of the HTML output via style sheets

Requirements

The toolkit requires PHP 4 or higher - Has been tested with PHP 4.3.7 and 4.3.8

Example Scripts

Included with the PHP JPEG Metadata Toolkit are several example scripts, which show how the library can be used to retrieve and store the metadata in a JPEG image file. Below are explanations of some of the commands used in the scripts.

FileDemo Description
Example.php Displays detailed information about the metadata in a JPEG file.
TIFFExample.php Displays detailed information about the metadata in a JPEG file.
Edit_File_Info_Example.php, Write_File_Info.php Allows editing of metadata over the internet in exactly the same format as Photoshop"s "File Info" dialog box.

Go here for Function reference, live demo, and further information

Click Here to Try It! - You might notice the Hindi characters, custom colours and that Photoshop CS wiped the EXIF makernote.

Version 1.12 [21/9/11] - Fixes to remove serious vulnerability found by Rocco Calvi

Galleries using the toolkit & other links

Download Now! Version 1.12 [GNU Public License]

Allows reading, writing and display of the following JPEG metadata formats

  • EXIF 2.2 - including makernotes
  • XMP / RDF, including multiple language support
  • Dublin Core
  • IPTC-NAA IIM 4.1
  • Photoshop IRB
  • Picture Info
  • JFIF
  • DCF 2.0
  • TIFF/EP
  • JFIF Extension
  • Embedded s
  • Intrinsic JPEG Values

Other features:

  • Tested with over 450 popular digital cameras - See here for details
  • Provides access to lots of metadata for which php has no built in support
  • Works with many files that have corrupted metadata.
  • Customisable look of the HTML output via style sheets
  • Works with PHP4 and does not require the --enable-exif extension
  • Allows metadata editing just like in Photoshop "File Info" box

More Information:

Email me your comments or questions:

electronics.ozhiker.com

www.ozhiker.com

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 , and 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 ];
                

Chủ Đề