📄 photoshop_file_info.php
字号:
/***************************************/ // 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] ) ) { $new_Exif_array[0][34665][0][36868] = array ( "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ]['EXIF'][ 36868 ]['Name'], "Tag Number" => 36868, "Data Type" => 2, "Type" => $GLOBALS[ "IFD_Tag_Definitions" ]['EXIF'][ 36868 ]['Type'], "Data" => $new_Exif_array[0][306]['Data'] ); } } // Photoshop changes the EXIF date Tag (306) to the current date, not the date that was entered in File Info $exif_date = date ( "Y:m:d H:i:s" ); // Update the EXIF Date and Time Tag with the new value $new_Exif_array[0][306] = array ( "Tag Name" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 306 ]['Name'], "Tag Number" => 306, "Data Type" => 2, "Type" => $GLOBALS[ "IFD_Tag_Definitions" ]['TIFF'][ 306 ]['Type'], "Data" => array( $exif_date ) ); // Photoshop replaces the EXIF Software or Firmware Tag with "Adobe Photoshop ..." // This toolkit instead preserves existing value and appends the toolkit name to the end of it // Check if the EXIF Software or Firmware Tag exists if ( array_key_exists( 305, $new_Exif_array[0] ) ) { // An existing EXIF Software or Firmware Tag was found // Check if the existing Software or Firmware Tag already contains the Toolkit's name if ( stristr ( $new_Exif_array[0][305]['Data'][0], $GLOBALS[ "Software Name" ]) == FALSE ) { // Toolkit Name string not found in the existing Software/Firmware string - append it. $firmware_str = $new_Exif_array[0][305]['Data'][0] . " " . $GLOBALS[ "Software Name" ]; } else { // Toolkit name already exists in Software/Firmware string - don't put another copy in the string
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -