用PHP GD嵌入IPTC图像数据
时间:2020-03-05 18:42:26 来源:igfitidea点击:
我正在尝试使用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源代码在这里可用,并且各自的输出是:
- 影像输出
- 数据输出
解决方案
回答
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); } ?>
希望这可以帮助...