我试图使用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源代码是可在这里,相应的输出是:
发布于 2008-08-23 19:19:46
getimagesize有一个可选的第二个参数Imageinfo,它包含您需要的信息。
从手册中:
此可选参数允许您从图像文件中提取一些扩展信息。目前,这将返回不同的JPG应用程序标记作为一个关联数组。一些程序使用这些应用程序标记在图像中嵌入文本信息。一个非常常见的方法是在APP13标记中嵌入IPTC信息。您可以使用
iptcparse()函数将二进制APP13标记解析为可读的内容。
所以你可以这样用它:
<?php
$size = getimagesize('./phplogo-edited.jpg', $info);
if(isset($info['APP13']))
{
$iptc = iptcparse($info['APP13']);
var_dump($iptc);
}
?>希望这能帮上忙。
https://stackoverflow.com/questions/24456
复制相似问题