Write an array of values in the "IPTC" Image

1.3k views Asked by At

I'm doing a class to handle the "IPTC" image and need to write some values to array as show in the example below;

[2#020] => Array //SUPPLEMENTAL_CATEGORY
    (
        [0] => SPORT
        [1] => REAL MADRID
    )


[2#025] => Array //KEYWORDS
    (
        [0] => value 1
        [1] => value 2
        [2] => value 3
    )

example of implementation that hope;

$iptc = new Iptc('some_image.jpg');
$iptc->set('KEYWORDS', array(
    'value 1',
    'value 2',
    'value 3'
));

can anyone help me with this?

Note: I'm using the "iptcembed" write the metatags in the image.

thanks!

1

There are 1 answers

1
Agutoli On

I even managed to solve the problem and I will share here how I did it;

$val = array('keyword1', 'keyword2', 'keyword3');
$rec  = 2;
$tag = 025;

if (is_array($val)) {
    $source = '';
    foreach($val as $item) {
        $len = strlen($item);
        $source .= chr(0x1c).chr($rec).chr($tag);
        $source .= chr($len >> 8).
                   chr($len & 0xff).
                   $item;
    }
    return $source;
}

Result

Array
(
    [0] => keyword1
    [1] => keyword2
    [2] => keyword3
)

Hug!