tags:

views:

842

answers:

2

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

Thanks, Ross

+1  A: 

Hi Ross,

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

crono
A: 

Oops, I thought that param was something completely different - thanks for that!

Ross