/add-ons/pjmt/Photoshop_File_Info.php
PHP | 2498 lines | 1215 code | 514 blank | 769 comment | 221 complexity | 97e084ed80b56ce2e576afed3824bafe MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
-
- /******************************************************************************
- *
- * Filename: Photoshop_File_Info.php
- *
- * Description: Provides functions that mimic the way Photoshop reads and writes
- * metadata in it's 'File Info' dialog
- *
- * Author: Evan Hunter
- *
- * Date: 11/11/2004
- *
- * Project: JPEG Metadata
- *
- * Revision: 1.11
- * Changes: 1.10 -> 1.11 : Changed displayed toolkit version numbers to reference Toolkit_Version.php
- *
- * URL: http://electronics.ozhiker.com
- *
- * License: This file is part of the PHP JPEG Metadata Toolkit.
- *
- * The PHP JPEG Metadata Toolkit is free software; you can
- * redistribute it and/or modify it under the terms of the
- * GNU General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * The PHP JPEG Metadata Toolkit is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with the PHP JPEG Metadata Toolkit; if not,
- * write to the Free Software Foundation, Inc., 59 Temple
- * Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * If you require a different license for commercial or other
- * purposes, please contact the author: evan@ozhiker.com
- *
- ******************************************************************************/
-
- // TODO: XMP sections: XAPMM, TIFF, EXIF
-
-
- include 'Toolkit_Version.php'; // Change: added as of version 1.11
-
-
- /******************************************************************************
- * Global Variable: Software Name
- *
- * Contents: The string that is appended to fields which store the name of
- * the software editor.
- *
- ******************************************************************************/
-
- $GLOBALS[ "Software Name" ] = "(PHP JPEG Metadata Toolkit v" . $GLOBALS['Toolkit_Version'] . ")"; // Change: Changed version numbers to reference Toolkit_Version.php - as of version 1.11
-
- /******************************************************************************
- * End of Global Variable: Software Name
- ******************************************************************************/
-
-
-
-
-
-
- /******************************************************************************
- *
- * Function: get_photoshop_file_info
- *
- * Description: Retrieves Photoshop 'File Info' metadata in the same way that Photoshop
- * does. The results are returned in an array as below:
- *
- * $file_info_array = array(
- * "title" => "",
- * "author" => "",
- * "authorsposition" => "", // Note: Not used in Photoshop 7 or higher
- * "caption" => "",
- * "captionwriter" => "",
- * "jobname" => "", // Note: Not used in Photoshop CS
- * "copyrightstatus" => "",
- * "copyrightnotice" => "",
- * "ownerurl" => "",
- * "keywords" => array( 0 => "", 1 => "", ... ),
- * "category" => "", // Note: Max 3 characters
- * "supplementalcategories" => array( 0 => "", 1 => "", ... ),
- * "date" => "", // Note: DATE MUST BE IN YYYY-MM-DD format
- * "city" => "",
- * "state" => "",
- * "country" => "",
- * "credit" => "",
- * "source" => "",
- * "headline" => "",
- * "instructions" => "",
- * "transmissionreference" => "",
- * "urgency" => "" );
- *
- * Parameters: Exif_array - an array containing the EXIF information to be
- * searched, as retrieved by get_EXIF_JPEG. (saves having to parse the EXIF again)
- * XMP_array - an array containing the XMP information to be
- * searched, as retrieved by read_XMP_array_from_text. (saves having to parse the XMP again)
- * IRB_array - an array containing the Photoshop IRB information
- * to be searched, as retrieved by get_Photoshop_IRB. (saves having to parse the IRB again)
- *
- * Returns: outputarray - an array as above, containing the Photoshop File Info data
- *
- ******************************************************************************/
-
- function get_photoshop_file_info( $Exif_array, $XMP_array, $IRB_array )
- {
-
- // Create a blank array to receive the output
- $outputarray = array(
- "title" => "",
- "author" => "",
- "authorsposition" => "",
- "caption" => "",
- "captionwriter" => "",
- "jobname" => "",
- "copyrightstatus" => "",
- "copyrightnotice" => "",
- "ownerurl" => "",
- "keywords" => array(),
- "category" => "",
- "supplementalcategories" => array(),
- "date" => "",
- "city" => "",
- "state" => "",
- "country" => "",
- "credit" => "",
- "source" => "",
- "headline" => "",
- "instructions" => "",
- "transmissionreference" => "",
- "urgency" => "" );
-
-
- /***************************************/
-
- // XMP Processing
-
-
- // Retrieve the dublin core section from the XMP header
-
- // Extract the Dublin Core section from the XMP
- $dublincore_block = find_XMP_block( $XMP_array, "dc" );
-
- // Check that the Dublin Core section exists
- if ( $dublincore_block != FALSE )
- {
- // Dublin Core Description Field contains caption
- // Extract Description
- $Item = find_XMP_item( $dublincore_block, "dc:description" );
-
- // Check if Description Tag existed
- if ( $Item != FALSE )
- {
- // Ensure that the Description value exists and save it.
- if ( ( array_key_exists( 'children', $Item ) ) &&
- ( $Item['children'][0]['tag'] == "rdf:Alt" ) &&
- ( array_key_exists( 'value', $Item['children'][0]['children'][0] ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'caption' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['value'] ), "\n" );
- }
- }
-
- /***************************************/
-
- // Dublin Core Creator Field contains author
- // Extract Description
- $Item = find_XMP_item( $dublincore_block, "dc:creator" );
-
- // Check if Creator Tag existed
- if ( $Item != FALSE )
- {
- // Ensure that the Creator value exists and save it.
- if ( ( array_key_exists( 'children', $Item ) ) &&
- ( $Item['children'][0]['tag'] =="rdf:Seq" ) &&
- ( array_key_exists( 'value', $Item['children'][0]['children'][0] ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'author' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['value'] ), "\n" );
- }
- }
-
- /***************************************/
-
- // Dublin Core Title Field contains title
- // Extract Title
- $Item = find_XMP_item( $dublincore_block, "dc:title" );
-
- // Check if Title Tag existed
- if ( $Item != FALSE )
- {
- // Ensure that the Title value exists and save it.
- if ( ( array_key_exists( 'children', $Item ) ) &&
- ( $Item['children'][0]['tag'] =="rdf:Alt" ) &&
- ( array_key_exists( 'value', $Item['children'][0]['children'][0] ) ) )
- {
-
- $outputarray = add_to_field( $outputarray, 'title' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['value'] ), "," );
- }
- }
-
- /***************************************/
-
- // Dublin Core Rights Field contains copyrightnotice
- // Extract Rights
- $Item = find_XMP_item( $dublincore_block, "dc:rights" );
-
- // Check if Rights Tag existed
- if ( $Item != FALSE )
- {
- // Ensure that the Rights value exists and save it.
- if ( ( array_key_exists( 'children', $Item ) ) &&
- ( $Item['children'][0]['tag'] =="rdf:Alt" ) &&
- ( array_key_exists( 'value', $Item['children'][0]['children'][0] ) ) )
- {
-
- $outputarray = add_to_field( $outputarray, 'copyrightnotice' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['value'] ), "," );
- }
- }
-
- /***************************************/
-
- // Dublin Core Subject Field contains keywords
- // Extract Subject
- $Item = find_XMP_item( $dublincore_block, "dc:subject" );
-
- // Check if Subject Tag existed
- if ( $Item != FALSE )
- {
- // Ensure that the Subject values exist
- if ( ( array_key_exists( 'children', $Item ) ) && ( $Item['children'][0]['tag'] =="rdf:Bag" ) )
- {
- // Cycle through each Subject value and save them
- foreach ( $Item['children'][0]['children'] as $keywords )
- {
- if ( ! in_array ( HTML_UTF8_Escape( $keywords['value'] ), $outputarray['keywords']))
- {
- if ( array_key_exists( 'value', $keywords ) )
- {
- $outputarray['keywords'][] = HTML_UTF8_Escape( $keywords['value'] );
- }
- }
- }
- }
- }
-
-
- }
-
- /***************************************/
-
- // Find the Photoshop Information within the XMP block
- $photoshop_block = find_XMP_block( $XMP_array, "photoshop" );
-
- // Check that the Photoshop Information exists
- if ( $photoshop_block != FALSE )
- {
- // The Photoshop CaptionWriter tag contains captionwriter - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:CaptionWriter" );
-
- // Check that the CaptionWriter Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'captionwriter' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop Headline tag contains headline - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:Headline" );
-
- // Check that the Headline Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'headline' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop Instructions tag contains instructions - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:Instructions" );
-
- // Check that the Instructions Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'instructions' , HTML_UTF8_Escape( $Item['value'] ), "\n" );
- }
-
- /***************************************/
-
- // The Photoshop AuthorsPosition tag contains authorsposition - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:AuthorsPosition" );
-
- // Check that the AuthorsPosition Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'authorsposition' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop Credit tag contains credit - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:Credit" );
-
- // Check that the Credit Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'credit' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop Source tag contains source - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:Source" );
-
- // Check that the Credit Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'source' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop City tag contains city - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:City" );
-
- // Check that the City Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'city' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop State tag contains state - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:State" );
-
- // Check that the State Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'state' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop Country tag contains country - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:Country" );
-
- // Check that the Country Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'country' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop TransmissionReference tag contains transmissionreference - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:TransmissionReference" );
-
- // Check that the TransmissionReference Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'transmissionreference' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop Category tag contains category - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:Category" );
-
- // Check that the TransmissionReference Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'category' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop DateCreated tag contains date - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:DateCreated" );
-
- // Check that the DateCreated Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'date' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop Urgency tag contains urgency - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:Urgency" );
-
- // Check that the Urgency Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'urgency' , HTML_UTF8_Escape( $Item['value'] ), "," );
- }
-
- /***************************************/
-
- // The Photoshop SupplementalCategories tag contains supplementalcategories - Find it
- $Item = find_XMP_item( $photoshop_block, "photoshop:SupplementalCategories" );
-
- // Check that the SupplementalCategories Field exists
- if ( $Item != FALSE )
- {
- // Check that the values exist
- if ( ( array_key_exists( 'children', $Item ) ) && ( $Item['children'][0]['tag'] =="rdf:Bag" ) )
- {
- // Cycle through the values and save them
- foreach ( $Item['children'][0]['children'] as $sup_category )
- {
- if ( ( array_key_exists( 'value', $sup_category ) ) &&
- ( ! in_array ( HTML_UTF8_Escape( $sup_category['value'] ), $outputarray['supplementalcategories'])) )
- {
- if ( array_key_exists( 'value', $sup_category ) )
- {
- $outputarray['supplementalcategories'][] = HTML_UTF8_Escape( $sup_category['value'] );
- }
- }
- }
- }
- }
-
- }
-
- /***************************************/
-
- // Find the Job Reference Information within the XMP block
- $job_block = find_XMP_block( $XMP_array, "xapBJ" );
-
- // Check that the Job Reference Information exists
- if ( $job_block != FALSE )
- {
- // The JobRef Field contains jobname - Find it
- $Item = find_XMP_item( $job_block, "xapBJ:JobRef" );
-
- // Check that the JobRef Field exists
- if ( $Item != FALSE )
- {
- // Check that the value exists and save it
- if ( ( array_key_exists( 'children', $Item ) ) &&
- ( $Item['children'][0]['tag'] =="rdf:Bag" ) &&
- ( array_key_exists( 'children', $Item['children'][0] ) ) &&
- ( $Item['children'][0]['children'][0]['tag'] =="rdf:li" ) &&
- ( array_key_exists( 'children', $Item['children'][0]['children'][0] ) ) &&
- ( $Item['children'][0]['children'][0]['children'][0]['tag'] =="stJob:name" ) &&
- ( array_key_exists( 'value', $Item['children'][0]['children'][0]['children'][0] ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'jobname' , HTML_UTF8_Escape( $Item['children'][0]['children'][0]['children'][0]['value'] ), "," );
- }
- }
- }
-
-
- /***************************************/
-
- // Find the Rights Information within the XMP block
- $rights_block = find_XMP_block( $XMP_array, "xapRights" );
-
- // Check that the Rights Information exists
- if ( $rights_block != FALSE )
- {
- // The WebStatement Field contains ownerurl - Find it
- $Item = find_XMP_item( $rights_block, "xapRights:WebStatement" );
-
- // Check that the WebStatement Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- $outputarray = add_to_field( $outputarray, 'ownerurl' , HTML_UTF8_Escape( $Item['value'] ), "\n" );
- }
-
- /***************************************/
-
- // The Marked Field contains copyrightstatus - Find it
- $Item = find_XMP_item( $rights_block, "xapRights:Marked" );
-
- // Check that the Marked Field exists and save the value
- if ( ( $Item != FALSE ) && ( array_key_exists( 'value', $Item ) ) )
- {
- if ( $Item['value'] == "True" )
- {
- $outputarray = add_to_field( $outputarray, 'copyrightstatus' , "Copyrighted Work", "," );
- }
- else
- {
- $outputarray = add_to_field( $outputarray, 'copyrightstatus' , "Public Domain", "," );
- }
- }
-
- }
-
-
-
-
-
- /***************************************/
-
- // Photoshop IRB Processing
-
- // Check that the Photoshop IRB exists
- if ( $IRB_array != FALSE )
- {
- // Create a translation table to convert carriage returns to linefeeds
- $irbtrans = array("\x0d" => "\x0a");
-
- // The Photoshop IRB Copyright flag (0x040A) contains copyrightstatus - find it
- $IRB_copyright_flag = find_Photoshop_IRB_Resource( $IRB_array, 0x040A );
-
- // Check if the Copyright flag Field exists, and save the value
- if( $IRB_copyright_flag != FALSE )
- {
- // Check the value of the copyright flag
- if ( hexdec( bin2hex( $IRB_copyright_flag['ResData'] ) ) == 1 )
- {
- // Save the value
- $outputarray = add_to_field( $outputarray, 'copyrightstatus' , "Copyrighted Work", "," );
- }
- else
- {
- // Do nothing - copyrightstatus will be set to unmarked if still blank at end
- }
- }
-
- /***************************************/
-
- // The Photoshop IRB URL (0x040B) contains ownerurl - find it
- $IRB_url = find_Photoshop_IRB_Resource( $IRB_array, 0x040B );
-
- // Check if the URL Field exists and save the value
- if( $IRB_url != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'ownerurl' , strtr( $IRB_url['ResData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // Extract any IPTC block from the Photoshop IRB information
- $IPTC_array = get_Photoshop_IPTC( $IRB_array );
-
- // Check if the IPTC block exits
- if ( ( $IPTC_array != FALSE ) && ( count( $IPTC_array ) != 0 ) )
- {
- // The IPTC Caption/Abstract Field contains caption - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:120" );
-
- // Check if the Caption/Abstract Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'caption' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Caption Writer/Editor Field contains captionwriter - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:122" );
-
- // Check if the Caption Writer/Editor Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'captionwriter' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Headline Field contains headline - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:105" );
-
- // Check if the Headline Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'headline' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Special Instructions Field contains instructions - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:40" );
-
- // Check if the Special Instructions Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'instructions' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC By-Line Field contains author - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:80" );
-
- // Check if the By-Line Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'author' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC By-Line Title Field contains authorsposition - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:85" );
-
- // Check if the By-Line Title Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'authorsposition' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Credit Field contains credit - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:110" );
-
- // Check if the Credit Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'credit' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Source Field contains source - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:115" );
-
- // Check if the Source Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'source' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Object Name Field contains title - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:05" );
-
- // Check if the Object Name Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'title' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Date Created Field contains date - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:55" );
-
- // Check if the Date Created Field exists and save the value
- if ( $record != FALSE )
- {
- $date_array = unpack( "a4Year/a2Month/A2Day", $record['RecData'] );
- $tmpdate = $date_array['Year'] . "-" . $date_array['Month'] . "-" . $date_array['Day'];
- $outputarray = add_to_field( $outputarray, 'date' , strtr( $tmpdate, $irbtrans ), "," );
-
- }
-
- /***************************************/
-
- // The IPTC City Field contains city - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:90" );
-
- // Check if the City Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'city' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Province/State Field contains state - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:95" );
-
- // Check if the Province/State Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'state' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Country/Primary Location Name Field contains country - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:101" );
-
- // Check if the Country/Primary Location Name Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'country' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Original Transmission Reference Field contains transmissionreference - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:103" );
-
- // Check if the Original Transmission Reference Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'transmissionreference' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- /***************************************/
-
- // The IPTC Category Field contains category - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:15" );
-
- // Check if the Category Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'category' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
-
- /***************************************/
-
- // Cycle through the IPTC records looking for Supplemental Category records
- foreach ($IPTC_array as $record)
- {
- // Check if a Supplemental Category record has been found
- if ( $record['IPTC_Type'] == "2:20" )
- {
- // A Supplemental Category record has been found, save it's value if the value doesn't already exist
- if ( ! in_array ( $record['RecData'], $outputarray['supplementalcategories']))
- {
- $outputarray['supplementalcategories'][] = strtr( $record['RecData'], array("\x0a" => "", "\x0d" => "
") ) ;
- }
- }
- }
-
-
- /***************************************/
-
- // The IPTC Urgency Field contains urgency - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:10" );
-
- // Check if the Urgency Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'urgency' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
-
-
- /***************************************/
-
- // Cycle through the IPTC records looking for Keywords records
- foreach ($IPTC_array as $record)
- {
- // Check if a Keywords record has been found
- if ( $record['IPTC_Type'] == "2:25" )
- {
- // A Keywords record has been found, save it's value if the value doesn't already exist
- if ( ! in_array ( $record['RecData'], $outputarray['keywords']))
- {
- $outputarray['keywords'][] = strtr( $record['RecData'], array("\x0a" => "", "\x0d" => "
") ) ;
- }
- }
- }
-
-
- /***************************************/
-
- // The IPTC Copyright Notice Field contains copyrightnotice - find it
- $record = find_IPTC_Resource( $IPTC_array, "2:116" );
-
- // Check if the Copyright Field exists and save the value
- if ( $record != FALSE )
- {
- $outputarray = add_to_field( $outputarray, 'copyrightnotice' , strtr( $record['RecData'], $irbtrans ), "\n" );
- }
-
- }
- }
-
-
-
-
- /***************************************/
-
- // EXIF Processing
-
-
- // Retreive Information from the EXIF data if it exists
-
- if ( ( $Exif_array != FALSE ) || ( count( $Exif_array ) == 0 ) )
- {
- // Check the Image Description Tag - it can contain the caption
- if ( array_key_exists( 270, $Exif_array[0] ) )
- {
- $outputarray = add_to_field( $outputarray, 'caption' , $Exif_array[0][270]['Data'][0], "\n" );
- }
-
- /***************************************/
-
- // Check the Copyright Information Tag - it contains the copyrightnotice
- if ( array_key_exists( 33432, $Exif_array[0] ) )
- {
- $outputarray = add_to_field( $outputarray, 'copyrightnotice' , HTML_UTF8_UnEscape( $Exif_array[0][33432]['Data'][0] ), "\n" );
- }
-
- /***************************************/
-
- // Check the Artist Name Tag - it contains the author
- if ( array_key_exists( 315, $Exif_array[0] ) )
- {
- $outputarray = add_to_field( $outputarray, 'author' , HTML_UTF8_UnEscape( $Exif_array[0][315]['Data'][0] ), "\n" );
- }
-
- }
-
-
- /***************************/
-
- // FINISHED RETRIEVING INFORMATION
-
- // Perform final processing
-
-
- // Check if any urgency information was found
- if ( $outputarray["urgency"] == "" )
- {
- // No urgency information was found - set it to default (None)
- $outputarray["urgency"] = "none";
- }
-
- // Check if any copyrightstatus information was found
- if ( $outputarray["copyrightstatus"] == "" )
- {
- // No copyrightstatus information was found - set it to default (Unmarked)
- $outputarray["copyrightstatus"] = "unmarked";
- }
-
- // Return the resulting Photoshop File Info Array
- return $outputarray;
-
- }
-
- /******************************************************************************
- * End of Function: get_photoshop_file_info
- ******************************************************************************/
-
-
-
-
-
-
- /******************************************************************************
- *
- * Function: put_photoshop_file_info
- *
- * Description: Stores Photoshop 'File Info' metadata in the same way that Photoshop
- * does. The 'File Info' metadata must be in an array similar to that
- * returned by get_photoshop_file_info, as follows:
- *
- * $file_info_array = array(
- * "title" => "",
- * "author" => "",
- * "authorsposition" => "", // Note: Not used in Photoshop 7 or higher
- * "caption" => "",
- * "captionwriter" => "",
- * "jobname" => "", // Note: Not used in Photoshop CS
- * "copyrightstatus" => "",
- * "copyrightnotice" => "",
- * "ownerurl" => "",
- * "keywords" => array( 0 => "", 1 => "", ... ),
- * "category" => "", // Note: Max 3 characters
- * "supplementalcategories" => array( 0 => "", 1 => "", ... ),
- * "date" => "", // Note: DATE MUST BE IN YYYY-MM-DD format
- * "city" => "",
- * "state" => "",
- * "country" => "",
- * "credit" => "",
- * "source" => "",
- * "headline" => "",
- * "instructions" => "",
- * "transmissionreference" => "",
- * "urgency" => "" );
- *
- * Parameters: jpeg_header_data - a JPEG header data array in the same format
- * as from get_jpeg_header_data. This contains the
- * header information which is to be updated.
- * new_ps_file_info_array - An array as above, which contains the
- * 'File Info' metadata information to be
- * written.
- * Old_Exif_array - an array containing the EXIF information to be
- * updated, as retrieved by get_EXIF_JPEG. (saves having to parse the EXIF again)
- * Old_XMP_array - an array containing the XMP information to be
- * updated, as retrieved by read_XMP_array_from_text. (saves having to parse the XMP again)
- * Old_IRB_array - an array containing the Photoshop IRB information
- * to be updated, as retrieved by get_Photoshop_IRB. (saves having to parse the IRB again)
- *
- * Returns: jpeg_header_data - a JPEG header data array in the same format
- * as from get_jpeg_header_data, containing the
- * Photshop 'File Info' metadata. This can then
- * be written to a file using put_jpeg_header_data.
- *
- ******************************************************************************/
-
- function put_photoshop_file_info( $jpeg_header_data, $new_ps_file_info_array, $Old_Exif_array, $Old_XMP_array, $Old_IRB_array )
- {
- /*******************************************/
- // PREPROCESSING
-
- // Check that the date is in the correct format (YYYY-MM-DD)
-
- // Explode the date into pieces using the - symbol
- $date_pieces = explode( "-", $new_ps_file_info_array[ 'date' ] );
-
- // If there are not 3 pieces to the date, it is invalid
- if ( count( $date_pieces ) != 3 )
- {
- // INVALID DATE
- echo "Invalid Date - must be YYYY-MM-DD format<br>";
- return FALSE;
- }
-
- // Cycle through each piece of the date
- foreach( $date_pieces as $piece )
- {
- // If the piece is not numeric, then the date is invalid.
- if ( ! is_numeric( $piece ) )
- {
- // INVALID DATE
- echo "Invalid Date - must be YYYY-MM-DD format<br>";
- return FALSE;
- }
- }
-
- // Make a unix timestamp at midnight on the date specified
- $date_stamp = mktime( 0,0,0, $date_pieces[1], $date_pieces[2], $date_pieces[0] );
-
-
-
-
- // Create a translation table to remove carriage return characters
- $trans = array( "\x0d" => "" );
-
- // Cycle through each of the File Info elements
- foreach( $new_ps_file_info_array as $valkey => $val )
- {
- // If the element is 'Keywords' or 'Supplemental Categories', then
- // it is an array, and needs to be treated as one
- if ( ( $valkey != 'supplementalcategories' ) && ( $valkey != 'keywords' ) )
- {
- // Not Keywords or Supplemental Categories
- // Convert escaped HTML characters to UTF8 and remove carriage returns
- $new_ps_file_info_array[ $valkey ] = strtr( HTML_UTF8_UnEscape( $val ), $trans );
- }
- else
- {
- // Either Keywords or Supplemental Categories
- // Cycle through the array,
- foreach( $val as $subvalkey => $subval )
- {
- // Convert escaped HTML characters to UTF8 and remove carriage returns
- $new_ps_file_info_array[ $valkey ][ $subvalkey ] = strtr( HTML_UTF8_UnEscape( $subval ), $trans );
- }
- }
- }
-
-
-
-
-
- /*******************************************/
-
- // EXIF Processing
-
-
- // Check if the EXIF array exists
- if( $Old_Exif_array == FALSE )
- {
- // EXIF Array doesn't exist - create a new one
- $new_Exif_array = array ( 'Byte_Align' => "MM",
- 'Makernote_Tag' => false,
- 'Tags Name' => "TIFF",
- 0 => array( "Tags Name" => "TIFF" ) );
- }
- else
- {
- // EXIF Array Does Exist - use it
- $new_Exif_array = $Old_Exif_array;
- }
-
-
-
- // Update the EXIF Image Description Tag with the new value
- $new_Exif_array[0][270] = array ( "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 270 ]['Name'],
- "Tag Number" => 270,
- "Data Type" => 2,
- "Type" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 270 ]['Type'],
- "Data" => array( HTML_UTF8_Escape( $new_ps_file_info_array[ 'caption' ]) ));
-
- // Update the EXIF Artist Name Tag with the new value
- $new_Exif_array[0][315] = array ( "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 315 ]['Name'],
- "Tag Number" => 315,
- "Data Type" => 2,
- "Type" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 315 ]['Type'],
- "Data" => array( HTML_UTF8_Escape( $new_ps_file_info_array[ 'author' ] ) ) );
-
- // Update the EXIF Copyright Information Tag with the new value
- $new_Exif_array[0][33432] = array ( "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 33432 ]['Name'],
- "Tag Number" => 33432,
- "Data Type" => 2,
- "Type" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 33432 ]['Type'],
- "Data" => array( HTML_UTF8_Escape( $new_ps_file_info_array[ 'copyrightnotice' ]) ) );
-
-
- // Photoshop checks if the "Date and Time of Original" and "Date and Time when Digitized" tags exist
- // If they don't exist, it means that the EXIF date may be wiped out if it is changed, so Photoshop
- // copies the EXIF date to these two tags
-
- if ( ( array_key_exists( 306, $new_Exif_array[0] ) )&&
- ( array_key_exists( 34665, $new_Exif_array[0] ) ) &&
- ( array_key_exists( 0, $new_Exif_array[0][34665] ) ) )
- {
- // Replace "Date and Time of Original" if it doesn't exist
- if ( ! array_key_exists( 36867, $new_Exif_array[0][34665][0] ) )
- {
- $new_Exif_array[0][34665][0][36867] = array ( "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ]['EXIF'][ 36867 ]['Name'],
- "Tag Number" => 36867,
- "Data Type" => 2,
- "Type" => $GLOBALS[ "IFD_Tag_Definitions" ]['EXIF'][ 36867 ]['Type'],
- "Data" => $new_Exif_array[0][306]['Data'] );
- }
-
- // Replace "Date and Time when Digitized" if it doesn't exist
- if ( ! array_key_exists( 36868, $new_Exif_array[0][34665][0] ) )
- {
- …
Large files files are truncated, but you can click here to view the full file