我正在尝试使用 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 ,各自的输出为:
最佳答案
getimagesize
有一个可选的第二个参数 Imageinfo
,其中包含您需要的信息。
来自手册:
This optional parameter allows you to extract some extended information from the image file. Currently, this will return the different JPG APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed » IPTC information in the APP13 marker. You can use the
iptcparse()
function to parse the binary APP13 marker into something readable.
所以你可以像这样使用它:
<?php
$size = getimagesize('./phplogo-edited.jpg', $info);
if(isset($info['APP13']))
{
$iptc = iptcparse($info['APP13']);
var_dump($iptc);
}
?>
希望这有帮助...
关于php - 使用 PHP GD 嵌入 IPTC 图像数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24456/