2

次のように、一部のコードが写真から変数にexifデータをフェッチするphpスクリプトがあります。

$exif_data = get_EXIF_JPEG( $filename );

注: 関数 'get_EXIF_JPEG( $filename )' は、'include' スクリプトから呼び出されます。

次に、変数の内容を出力して、特定の 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

含まれているphpファイルからのget_exif_jpegのコードは次のとおりです

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

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 に答える