使用PHP GD嵌入IPTC图像数据 [英] Embedding IPTC image data with PHP GD
问题描述
我正在尝试使用iptcembed()
将IPTC数据嵌入到JPEG图像上,但是有点麻烦.
I'm trying to embed a IPTC data onto a JPEG image using iptcembed()
but am having a bit of trouble.
我已确认它已在最终产品中
I have verified it is in the end product:
// Embed the IPTC data
$content = iptcembed($data, $path);
// Verify IPTC data is in the end image
$iptc = iptcparse($content);
var_dump($iptc);
哪个返回输入的标签.
但是,当我保存并重新加载图像时,标记不存在:
However when I save and reload the image the tags are non existant:
// 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);
}
那为什么保存的图像中没有标签?
So why aren't the tags in the saved image?
PHP源为此处可用,并且相应的输出是:
The PHP source is avaliable here, and the respective outputs are:
- Image output
- Data output
推荐答案
getimagesize
具有可选的第二个参数Imageinfo
,其中包含您需要的信息.
getimagesize
has an optional second parameter Imageinfo
which contains the info you need.
从手册中:
此可选参数允许您从图像文件中提取一些扩展信息.当前,这将以关联数组的形式返回不同的JPG APP标记.一些程序使用这些APP标记在图像中嵌入文本信息.一种非常常见的方法是将IPTC信息嵌入APP13标记中.您可以使用
iptcparse()
函数将二进制APP13标记解析为可读的内容.
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.
所以您可以像这样使用它:
so you could use it like this:
<?php
$size = getimagesize('./phplogo-edited.jpg', $info);
if(isset($info['APP13']))
{
$iptc = iptcparse($info['APP13']);
var_dump($iptc);
}
?>
希望这对您有帮助...
Hope this helps...
这篇关于使用PHP GD嵌入IPTC图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!