使用PHP GD嵌入IPTC图像数据

问题描述 投票:2回答:1

我正在尝试使用iptcembed()将IPTC数据嵌入到JPEG图像中,但我遇到了一些麻烦。

我已经确认它是最终产品:

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

// Verify IPTC data is in the end image
$iptc = iptcparse($content);
var_dump($iptc);

返回输入的标签。

但是,当我保存并重新加载图像时,标签不存在:

// Save the edited image
$im = imagecreatefromstring($content);
imagejpeg($im, 'phplogo-edited.jpg');
imagedestroy($im);

// Get data from the saved image
$image = getimagesize('./phplogo-edited.jpg');

// If APP13/IPTC data exists output it
if(isset($image['APP13']))
{
    $iptc = iptcparse($image['APP13']);
    print_r($iptc);
}
else
{
    // Otherwise tell us what the image *does* contain
    // SO: This is what's happening
    print_r($image);
}

那么为什么保存图像中的标签不是?

PHP源代码是avaliable here,各自的输出是:

  1. Image output
  2. Data output
php gd iptc
1个回答
3
投票

getimagesize有一个可选的第二个参数Imageinfo,其中包含您需要的信息。

从手册:

此可选参数允许您从图像文件中提取一些扩展信息。目前,这将返回不同的JPG APP标记作为关联数组。某些程序使用这些APP标记在文档中嵌入文本信息。一个非常常见的方法是在APP13标记中嵌入»IPTC信息。您可以使用iptcparse()函数将二进制APP13标记解析为可读的内容。

所以你可以像这样使用它:

<?php
$size = getimagesize('./phplogo-edited.jpg', $info);
if(isset($info['APP13']))
{
    $iptc = iptcparse($info['APP13']);
    var_dump($iptc);
}
?>

希望这可以帮助...

© www.soinside.com 2019 - 2024. All rights reserved.