Embedding IPTC image data with PHP GD

允我心安 提交于 2019-12-07 18:33:43

问题


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

Which returns the tags entered.

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?

The PHP source is avaliable here, and the respective outputs are:

  1. Image output
  2. Data output

回答1:


getimagesize has an optional second parameter Imageinfo which contains the info you need.

From the manual:

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



来源:https://stackoverflow.com/questions/24456/embedding-iptc-image-data-with-php-gd

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!