⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exif.php

📁 CMS系统 提供学习研究修改最好了 比流行的一些CMS简单 但是更容易理解 是帮助你学习PHPCMS系统的好东东哦
💻 PHP
📖 第 1 页 / 共 5 页
字号:
                echo "\$newfilename = tempnam ( \$dir, \"tmpmeta\" );<br>\n";
                echo "copy ( \"http://whatever.com\", \$newfilename );<br><br>\n";
                return FALSE;
        }

        // get the JPEG headers
        $jpeg_header_data = get_jpeg_header_data( $filename );


        // Flag that an Meta segment has not been found yet
        $Meta_Location = -1;

        //Cycle through the header segments
        for( $i = 0; $i < count( $jpeg_header_data ); $i++ )
        {
                // If we find an APP3 header,
                if  ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP3" ) == 0 )
                {
                        // And if it has the Meta label,
                        if ( ( strncmp ( $jpeg_header_data[$i]['SegData'], "Meta\x00\x00", 6) == 0 ) ||
                             ( strncmp ( $jpeg_header_data[$i]['SegData'], "META\x00\x00", 6) == 0 ) )
                        {
                                // Save the location of the Meta segment
                                $Meta_Location = $i;
                        }
                }
        }

        // Check if an EXIF segment was found
        if ( $Meta_Location == -1 )
        {
                // Couldn't find any Meta block to decode
                return FALSE;
        }


        $filehnd = @fopen($filename, 'rb');

        // Check if the file opened successfully
        if ( ! $filehnd  )
        {
                // Could't open the file - exit
                echo "<p>Could not open file $filename</p>\n";
                return FALSE;
        }

        fseek( $filehnd, $jpeg_header_data[$Meta_Location]['SegDataStart'] + 6 );

        // Decode the Meta segment into an array and return it
        $meta = process_TIFF_Header( $filehnd, "Meta" );

         // Close File
        fclose($filehnd);

        return $meta;
}

/******************************************************************************
* End of Function:     get_Meta
******************************************************************************/







/******************************************************************************
*
* Function:     put_Meta_JPEG
*
* Description:  Stores information into a Meta APP3 segment from a Meta array.
*
*
*               WARNING: Because the Meta (EXIF) standard allows pointers to data
*               outside the APP1 segment, if there are any such pointers in
*               a makernote, this function will DAMAGE them since it will not
*               be aware that there is an external pointer. This will often
*               happen with Makernotes that include an embedded thumbnail.
*               This damage could be prevented where makernotes can be decoded,
*               but currently this is not implemented.
*
*
* Parameters:   meta_data - The array of Meta data to insert into the JPEG header
*               jpeg_header_data - The JPEG header into which the Meta data
*                                  should be stored, as from get_jpeg_header_data
*
* Returns:      jpeg_header_data - JPEG header array with the Meta segment inserted
*               FALSE - If an error occured
*
******************************************************************************/

function put_Meta_JPEG( $meta_data, $jpeg_header_data )
{
        // pack the Meta data into its proper format for a JPEG file
        $packed_data = get_TIFF_Packed_Data( $meta_data );
        if ( $packed_data === FALSE )
        {
                return $jpeg_header_data;
        }

        $packed_data = "Meta\x00\x00$packed_data";

        //Cycle through the header segments
        for( $i = 0; $i < count( $jpeg_header_data ); $i++ )
        {
                // If we find an APP1 header,
                if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP3" ) == 0 )
                {
                        // And if it has the Meta label,
                        if ( ( strncmp ( $jpeg_header_data[$i]['SegData'], "Meta\x00\x00", 6) == 0 ) ||
                             ( strncmp ( $jpeg_header_data[$i]['SegData'], "META\x00\x00", 6) == 0 ) )
                        {
                                // Found a preexisting Meta block - Replace it with the new one and return.
                                $jpeg_header_data[$i]['SegData'] = $packed_data;
                                return $jpeg_header_data;
                        }
                }
        }
        // No preexisting segment segment found, insert a new one at the start of the header data.

        // Determine highest position of an APP segment at or below APP3, so we can put the
        // new APP3 at this position


        $highest_APP = -1;

        //Cycle through the header segments
        for( $i = 0; $i < count( $jpeg_header_data ); $i++ )
        {
                // Check if we have found an APP segment at or below APP3,
                if ( ( $jpeg_header_data[$i]['SegType'] >= 0xE0 ) && ( $jpeg_header_data[$i]['SegType'] <= 0xE3 ) )
                {
                        // Found an APP segment at or below APP12
                        $highest_APP = $i;
                }
        }

        // No preexisting Meta block found, insert a new one at the start of the header data.
        array_splice($jpeg_header_data, $highest_APP + 1 , 0, array( array(     "SegType" => 0xE3,
                                                                                "SegName" => "APP3",
                                                                                "SegDesc" => $GLOBALS[ "JPEG_Segment_Descriptions" ][ 0xE1 ],
                                                                                "SegData" => $packed_data ) ) );
        return $jpeg_header_data;

}

/******************************************************************************
* End of Function:     put_Meta_JPEG
******************************************************************************/



/******************************************************************************
*
* Function:     get_EXIF_TIFF
*
* Description:  Retrieves information from a Exchangeable Image File Format (EXIF)
*               within a TIFF file and returns it in an array.
*
* Parameters:   filename - the filename of the TIFF image to process
*
* Returns:      OutputArray - Array of EXIF records
*               FALSE - If an error occured in decoding
*
******************************************************************************/

function get_EXIF_TIFF( $filename )
{
        // Change: Added as of version 1.11
        // Check if a wrapper is being used - these are not currently supported (see notes at top of file)
        if ( ( stristr ( $filename, "http://" ) != FALSE ) || ( stristr ( $filename, "ftp://" ) != FALSE ) )
        {
                // A HTTP or FTP wrapper is being used - show a warning and abort
                echo "HTTP and FTP wrappers are currently not supported with TIFF - See EXIF/TIFF functionality documentation - a local file must be specified<br>";
                echo "To work on an internet file, copy it locally to start with:<br><br>\n";
                echo "\$newfilename = tempnam ( \$dir, \"tmptiff\" );<br>\n";
                echo "copy ( \"http://whatever.com\", \$newfilename );<br><br>\n";
                return FALSE;
        }


        $filehnd = @fopen($filename, 'rb');

        // Check if the file opened successfully
        if ( ! $filehnd  )
        {
                // Could't open the file - exit
                echo "<p>Could not open file $filename</p>\n";
                return FALSE;
        }

        // Decode the Exif segment into an array and return it
        $exif_data = process_TIFF_Header( $filehnd, "TIFF" );

        // Close File
        fclose($filehnd);
        return $exif_data;
}

/******************************************************************************
* End of Function:     get_EXIF_TIFF
******************************************************************************/




/******************************************************************************
*
* Function:     Interpret_EXIF_to_HTML
*
* Description:  Generates html detailing the contents an APP1 EXIF array
*               which was retrieved with a get_EXIF_.... function.
*               Can also be used for APP3 Meta arrays.
*
* Parameters:   Exif_array - the EXIF array,as read from get_EXIF_....
*               filename - the name of the Image file being processed ( used
*                          by scripts which displays EXIF thumbnails)
*
* Returns:      output_str - A string containing the HTML
*
******************************************************************************/

function Interpret_EXIF_to_HTML( $Exif_array, $filename )
{
        // Create the string to receive the html output
        $output_str = "";

        // Check if the array to process is valid
        if ( $Exif_array === FALSE )
        {
                // Exif Array is not valid - abort processing
                return $output_str;
        }

        // Ouput the heading according to what type of tags were used in processing
        if ( $Exif_array[ 'Tags Name' ] == "TIFF" )
        {
                $output_str .= "<h2 class=\"EXIF_Main_Heading\">Contains Exchangeable Image File Format (EXIF) Information</h2>\n";
        }
        else if ( $Exif_array[ 'Tags Name' ] == "Meta" )
        {
                $output_str .= "<h2 class=\"EXIF_Main_Heading\">Contains META Information (APP3)</h2>\n";
        }
        else
        {
                $output_str .= "<h2 class=\"EXIF_Main_Heading\">Contains " . $Exif_array[ 'Tags Name' ] . " Information</h2>\n";
        }


        // Check that there are actually items to process in the array
        if ( count( $Exif_array ) < 1 )
        {
                // No items to process in array - abort processing
                return $output_str;
        }

        // Output secondary heading
        $output_str .= "<h3 class=\"EXIF_Secondary_Heading\">Main Image Information</h2>\n";

        // Interpret the zeroth IFD to html
        $output_str .= interpret_IFD( $Exif_array[0], $filename, $Exif_array['Byte_Align'] );

        // Check if there is a first IFD to process
        if ( array_key_exists( 1, $Exif_array ) )
        {
                // There is a first IFD for a thumbnail
                // Add a heading for it to the output
                $output_str .= "<h3 class=\"EXIF_Secondary_Heading\">Thumbnail Information</h2>\n";

                // Interpret the IFD to html and add it to the output
                $output_str .= interpret_IFD( $Exif_array[1], $filename, $Exif_array['Byte_Align'] );
        }

        // Cycle through any other IFD's
        $i = 2;
        while ( array_key_exists( $i, $Exif_array ) )
        {
                // Add a heading for the IFD
                $output_str .= "<h3  class=\"EXIF_Secondary_Heading\">Image File Directory (IFD) $i Information</h2>\n";

                // Interpret the IFD to html and add it to the output
                $output_str .= interpret_IFD( $Exif_array[$i], $filename, $Exif_array['Byte_Align'] );
                $i++;
        }

        // Return the resulting HTML
        return $output_str;
}

/******************************************************************************
* End of Function:     Interpret_EXIF_to_HTML
******************************************************************************/











⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -