使用PHP更改图像文件的EXIF数据

使用PHP更改图像文件的EXIF数据,php,Php,我已经使用以下代码成功地更改了IPTC标签。但无法修改EXIF元数据,如作者、描述等。以下是我用于IPTC的代码: <?php function iptc_make_tag($rec, $data, $value) { $length = strlen($value); $retval = chr(0x1C) . chr($rec) . chr($data); if($length < 0x8000) { $retval .= ch

我已经使用以下代码成功地更改了IPTC标签。但无法修改EXIF元数据,如作者、描述等。以下是我用于IPTC的代码:

<?php

function iptc_make_tag($rec, $data, $value)
{
    $length = strlen($value);
    $retval = chr(0x1C) . chr($rec) . chr($data);

    if($length < 0x8000)
    {
        $retval .= chr($length >> 8) .  chr($length & 0xFF);
    }
    else
    {
        $retval .= chr(0x80) . 
                   chr(0x04) . 
                   chr(($length >> 24) & 0xFF) . 
                   chr(($length >> 16) & 0xFF) . 
                   chr(($length >> 8) & 0xFF) . 
                   chr($length & 0xFF);
    }

    return $retval . $value;
}

// Path to jpeg file
$path = 'test.jpg';

// Set the IPTC tags
$iptc = array(
    '2#105' => 'Headline Here',
    '2#005' => 'Title Here',
    '2#120' => 'Caption Here',
    '2#116' => 'Copyright Here',
    '2#025' => 'KW Here',
    '2#110' => 'Credit Here',
    '2#080' => 'Creator here',



);

// Convert the IPTC tags into binary code
$data = '';

foreach($iptc as $tag => $string)
{
    $tag = substr($tag, 2);
    $data .= iptc_make_tag(2, $tag, $string);
}

// Embed the IPTC data
$content = iptcembed($data, $path);

// Write the new image data out to the file.
$fp = fopen($path, "wb");
fwrite($fp, $content);
fclose($fp);
?>

当我使用网站检查图像元时,它显示IPTC标签,但EXIF general字段为空。

代码正常,我在服务器上进行了测试。
文件或文件夹必须具有写入权限,才能在PHP7.2上运行。

它在服务器上运行很好,但了解您使用的PHP版本、安装的扩展名以及复制它的其他有用信息会更有帮助