2

我有一个 php 脚本,其中一些代码将 exif 数据从照片中提取到一个变量中,如下所示:

$exif_data = get_EXIF_JPEG( $filename );

注意:函数“get_EXIF_JPEG($filename)”是从“包含”脚本中调用的。

然后我打印了变量的内容,以了解某些 exif 信息是如何保存在变量中的:

var_dump ($exif_data);

对于有兴趣查看变量完整内容的任何人,可以使用此链接查看 - http://uko.com/testexif2/phptest.php

结果中有一个部分包含相机记录的照片大小。该部分的内容是:

[40962]=> array(9) { ["Tag Number"]=> int(40962) ["Tag Name"]=> string(17) "Pixel X Dimension" ["Tag Description"]=> string(0) "" ["Data Type"]=> int(4) ["Type"]=> string(7) "Numeric" ["Units"]=> string(6) "pixels" ["Data"]=> array(1) { [0]=> int(4000) } ["Text Value"]=> string(11) "4000 pixels" ["Decoded"]=> bool(true) }

我想更改它的内容以更改记录的图像大小,并找到了一些导致我尝试此代码的信息(在脚本开头指定了 $new_width):

$exif_data[40962]['Data'][0] = $new_width;
$exif_data[40962]['Text Value'] = $new_width . ' pixels';

这显然是不对的,因为它不会改变现有数据,它所做的只是将信息添加到变量中保存的数据的末尾。

任何人都可以告诉我必要的代码应该是什么 - 或者指出我可以在哪里获得一些信息来帮助的方向。

4

2 回答 2

0

Here is the code for get_exif_jpeg from the included php file

******************************************************************************/

function get_EXIF_JPEG( $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 EXIF - See EXIF 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, \"tmpexif\" );<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 EXIF segment has not been found yet
        $EXIF_Location = -1;

        //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'], "APP1" ) == 0 )
                {
                        // And if it has the EXIF label,
                        if ( ( strncmp ( $jpeg_header_data[$i]['SegData'], "Exif\x00\x00", 6) == 0 ) ||
                             ( strncmp ( $jpeg_header_data[$i]['SegData'], "Exif\x00\xFF", 6) == 0 ) )          // For some reason, some files have a faulty EXIF name which has a 0xFF in it
                        {
                                // Save the location of the EXIF segment
                                $EXIF_Location = $i;
                        }
                }

        }

        // Check if an EXIF segment was found
        if ( $EXIF_Location == -1 )
        {
                // Couldn't find any EXIF 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[$EXIF_Location]['SegDataStart'] + 6  );

        // 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_JPEG
于 2013-05-15T13:09:37.480 回答
0

你错过了一级

$exif_data[0][40962]['Data'][0] = $new_width;
$exif_data[0][40962]['Text Value'] = $new_width . ' pixels';
于 2013-05-15T12:48:35.147 回答