2008-08-23 35 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