Embedding IPTC Image Data Using PHP GD

I am trying to insert IPTC data into a JPEG image using iptcembed(), but I have some problems.

I checked that it is in the final product:

// Embed the IPTC data
$content = iptcembed($data, $path);

// Verify IPTC data is in the end image
$iptc = iptcparse($content);
var_dump($iptc);

Returns the entered tags.

However, when I save and reload the image, the tags do not exist:

// 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 happening
    print_r($image);
}

So why are there no tags in the saved image?

The PHP source is available here , and the corresponding outputs are:

+2
source share
1 answer

getimagesizehas an optional second parameter Imageinfothat contains the necessary information.

From the manual:

. APP JPG . APP . IPTC APP13. iptcparse() APP13 - .

:

<?php
$size = getimagesize('./phplogo-edited.jpg', $info);
if(isset($info['APP13']))
{
    $iptc = iptcparse($info['APP13']);
    var_dump($iptc);
}
?>

, ...

+3

All Articles