📄 nikon.php
字号:
<?php
/******************************************************************************
*
* Filename: Nikon.php
*
* Description: Nikon Makernote Parser
* Provides functions to decode an Nikon EXIF makernote and to interpret
* the resulting array into html.
*
* Nikon Makernote Format:
*
* Type 1
*
* Field Size Description
* ----------------------------------------------------------------
* Header 8 Bytes "Nikon\x00\x01\x00"
* IFD Data Variable Standard IFD Data using Nikon Type 1 Tags
* ----------------------------------------------------------------
*
* Type 2
*
* Field Size Description
* ----------------------------------------------------------------
* IFD Data Variable Standard IFD Data using Nikon Type 3 Tags
* ----------------------------------------------------------------
*
* Type 3
*
* Field Size Description
* ----------------------------------------------------------------
* Header 10 Bytes "Nikon\x00\x02\x10\x00\x00"
* or
* "Nikon\x00\x02\x00\x00\x00"
* TIFF Data Variable TIFF header, with associated
* Standard IFD Data using, Nikon
* Type 3 Tags. Offsets are from
* this second tiff header
* ----------------------------------------------------------------
*
* // Note: The Nikon Coolpix 775 uses the Fujifilm makernote format
*
*
*
* Author: Evan Hunter
*
* Date: 30/7/2004
*
* Project: JPEG Metadata
*
* Revision: 1.00
*
* URL: http://electronics.ozhiker.com
*
* Copyright: Copyright Evan Hunter 2004
* This file may be used freely for non-commercial purposes.For
* commercial uses please contact the author: evan@ozhiker.com
*
******************************************************************************/
// Add the parser and interpreter functions to the list of Makernote parsers and interpreters.
$GLOBALS['Makernote_Function_Array']['Read_Makernote_Tag'][] = "get_Nikon_Makernote";
$GLOBALS['Makernote_Function_Array']['get_Makernote_Text_Value'][] = "get_Nikon_Text_Value";
$GLOBALS['Makernote_Function_Array']['Interpret_Makernote_to_HTML'][] = "get_Nikon_Makernote_Html";
/******************************************************************************
*
* Function: get_Nikon_Makernote
*
* Description: Decodes the Makernote tag and returns the new tag with the decoded
* information attached. Returns false if this is not a makernote
* that can be processed with this script
*
* Parameters: Makernote_Tag - the element of an EXIF array containing the
* makernote, as returned from get_EXIF_JPEG
* EXIF_Array - the entire EXIF array containing the
* makernote, as returned from get_EXIF_JPEG, in
* case more information is required for decoding
* filehnd - an open file handle for the file containing the
* makernote - does not have to be positioned at the
* start of the makernote
* Make_Field - The contents of the EXIF Make field, to aid
* determining whether this script can decode
* the makernote
*
*
* Returns: Makernote_Tag - the Makernote_Tag from the parameters, but
* modified to contain the decoded information
* FALSE - If this script could not decode the makernote, or if
* an error occured in decoding
*
******************************************************************************/
function get_Nikon_Makernote( $Makernote_Tag, $EXIF_Array, $filehnd, $Make_Field )
{
// Check if the Make Field contains the word Nikon
if ( stristr( $Make_Field, "Nikon" ) === FALSE )
{
// Nikon not found in maker field - abort
return FALSE;
}
// Check if the header exists at the start of the Makernote
if ( substr( $Makernote_Tag['Data'],0 , 8 ) == "Nikon\x00\x01\x00" )
{
// Nikon Type 1 Makernote
// Seek to the start of the IFD
fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 8 );
// Read the IFD(s) into an array
$Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Nikon Type 1" );
// Save some information into the Tag element to aid interpretation
$Makernote_Tag['Decoded'] = TRUE;
$Makernote_Tag['Makernote Type'] = "Nikon Type 1";
$Makernote_Tag['Makernote Tags'] = "Nikon Type 1";
// Return the new tag
return $Makernote_Tag;
}
else if ( ( substr( $Makernote_Tag['Data'],0 , 10 ) == "Nikon\x00\x02\x10\x00\x00" ) ||
( substr( $Makernote_Tag['Data'],0 , 10 ) == "Nikon\x00\x02\x00\x00\x00" ) )
{
// Nikon Type 3 Makernote
// Seek to the start of the IFD
fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 10 );
// Read the TIFF header and IFD(s) into an array
$Makernote_Tag['Decoded Data'] = process_TIFF_Header( $filehnd, "Nikon Type 3" );
// Save some information into the Tag element to aid interpretation
$Makernote_Tag['Makernote Type'] = "Nikon Type 3";
$Makernote_Tag['Makernote Tags'] = "Nikon Type 3";
$Makernote_Tag['Decoded'] = TRUE;
// Return the new tag
return $Makernote_Tag;
}
else if ( substr( $Makernote_Tag['Data'],0 , 8 ) == "FUJIFILM" )
{
// Fuji Makernote - used by Nikon Coolpix 775
// Let the Fujifilm library handle it
return False;
}
else
{
// No header - Nikon Type 2
// Seek to the start of the IFD
fseek($filehnd, $Makernote_Tag['Tiff Offset'] + $Makernote_Tag['Offset'] + 0 );
// Read the IFD(s) into an array
$Makernote_Tag['Decoded Data'] = read_Multiple_IFDs( $filehnd, $Makernote_Tag['Tiff Offset'], $Makernote_Tag['ByteAlign'], "Nikon Type 3" );
// Save some information into the Tag element to aid interpretation
$Makernote_Tag['Decoded'] = TRUE;
$Makernote_Tag['Makernote Type'] = "Nikon Type 2";
$Makernote_Tag['Makernote Tags'] = "Nikon Type 3";
// Return the new tag
return $Makernote_Tag;
}
// Shouldn't get here
return FALSE;
}
/******************************************************************************
* End of Function: get_Nikon_Makernote
******************************************************************************/
/******************************************************************************
*
* Function: get_Nikon_Text_Value
*
* Description: Provides a text value for any tag marked as special for makernotes
* that this script can decode. Returns false if this is not a makernote
* that can be processed with this script
*
* Parameters: Exif_Tag - the element of an the Makernote array containing the
* tag in question, as returned from get_Nikon_Makernote
* Tag_Definitions_Name - The name of the Tag Definitions group
* within the global array IFD_Tag_Definitions
*
*
* Returns: output - the text value for the tag
* FALSE - If this script could not decode the makernote, or if
* an error occured in decoding
*
******************************************************************************/
function get_Nikon_Text_Value( $Exif_Tag, $Tag_Definitions_Name )
{
// Check that this tag uses the Nikon tags, otherwise it can't be interpreted here
// And check which variety of tags
if ( $Tag_Definitions_Name == "Nikon Type 1" )
{
// No special tags for Nikon type 1 so far
return FALSE;
}
else if ( $Tag_Definitions_Name == "Nikon Type 3" )
{
// Nikon Type 3 special tag
// Process tag according to it's tag number
if ( $Exif_Tag['Tag Number'] == 1) // Nikon Makernote Version - some are binary, some are text
{
return "\"" .HTML_UTF8_Escape( $Exif_Tag['Data'] ) . "\" (" . bin2hex( $Exif_Tag['Data'] ) . " hex)";
}
else if ( ( $Exif_Tag['Tag Number'] == 2 ) || // ISO Speed Used
( $Exif_Tag['Tag Number'] == 19 ) ) // ISO Speed Requested
{
// ISO speed settings - should be the second of two values
if ( count( $Exif_Tag['Data'] ) == 2 )
{
// There are two values - display the second
return $Exif_Tag['Data'][1] . " " . $Exif_Tag['Units'];
}
else
{
// There is not two values - display generic version of values
return get_IFD_value_as_text( $Exif_Tag['Data'] ) . " " . $Exif_Tag['Units'];
}
}
else if ( $Exif_Tag['Tag Number'] == 137 ) // Bracketing & Shooting Mode
{
// Add shooting mode to output from first two bits
switch ( $Exif_Tag['Data'][0] & 0x03 )
{
case 0x00:
$outputstr = "Shooting Mode: Single Frame\n";
break;
case 0x01:
$outputstr = "Shooting Mode: Continuous\n";
break;
case 0x02:
$outputstr = "Shooting Mode: Self Timer\n";
break;
case 0x03:
$outputstr = "Shooting Mode: Remote??\n";
break;
default:
$outputstr = "Shooting Mode: Unknown\n";
break;
}
// Add flash bracketing to output from fifth bit
if ( ( $Exif_Tag['Data'][0] & 0x10 ) == 0x10 )
{
$outputstr .= "AE/Flash Bracketing On\n";
}
else
{
$outputstr .= "AE/Flash Bracketing Off\n";
}
// Add white balance bracketing to output from seventh bit
if ( ( $Exif_Tag['Data'][0] & 0x40 ) == 0x40 )
{
$outputstr .= "White Balance Bracketing On\n";
}
else
{
$outputstr .= "White Balance Bracketing Off\n";
}
// Return the output
return $outputstr;
}
else if ( $Exif_Tag['Tag Number'] == 136 ) // Auto Focus Area
{
// Create a string to receive the output
$outputstr = "";
// If all zeros, this could be manual focus
if ( $Exif_Tag['Data'] == "\x00\x00\x00\x00" )
{
$outputstr .= "Manual Focus, or\n";
}
// Add AF mode according to the first byte
switch ( ord($Exif_Tag['Data']{0}) )
{
case 0x00:
$outputstr .= "Auto Focus Mode: Single Area\n";
break;
case 0x01:
$outputstr .= "Auto Focus Mode: Dynamic Area\n";
break;
case 0x02:
$outputstr .= "Auto Focus Mode: Closest Subject\n";
break;
default:
$outputstr .= "Auto Focus Mode: Unknown AF Mode\n";
break;
}
// Add AF area according to second byte
switch ( ord($Exif_Tag['Data']{1}) )
{
case 0x00:
$outputstr .= "Auto Focus Area Selected: Centre\n";
break;
case 0x01:
$outputstr .= "Auto Focus Area Selected: Top\n";
break;
case 0x02:
$outputstr .= "Auto Focus Area Selected: Bottom\n";
break;
case 0x03:
$outputstr .= "Auto Focus Area Selected: Left\n";
break;
case 0x04:
$outputstr .= "Auto Focus Area Selected: Right\n";
break;
}
// Add properly focused areas to output according to byte 3 bits
$outputstr .= "Properly Focused Area(s): ";
if ( ord($Exif_Tag['Data']{3}) == 0x00 )
{
$outputstr .= "None";
}
if ( ( ord($Exif_Tag['Data']{3}) & 0x01 ) == 0x01 )
{
$outputstr .= "Centre ";
}
if ( ( ord($Exif_Tag['Data']{3}) & 0x02 ) == 0x02 )
{
$outputstr .= "Top ";
}
if ( ( ord($Exif_Tag['Data']{3}) & 0x04 ) == 0x04 )
{
$outputstr .= "Bottom ";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -