2008-08-23 88 views
2

我试图将IPTC数据嵌入到使用iptcembed()的JPEG图像中,但我有点麻烦。用PHP嵌入IPTC图像数据GD

我已经验证它是中端产品:

// 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

回答

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); 
} 
?> 

希望这有助于...

+0

哎呀,我还以为是PARAM东西完全不同 - 对于谢谢! – Ross 2011-02-07 12:40:09