Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy the IPTC data from one image to another?

Tags:

php

metadata

iptc

I'm developing an image processor script to basically resize images. The problem is that when I make the resized copy of the image, it doesn't copy the IPTC data as well. So I've been checking the IPTC PHP functions (iptcparse and iptcembed) but I'm quite confused. Using iptcparse is very simple. It gets all the data into an array and then I print it out with print_r. But the supposedly useful one is iptcembed because it allows you to (as the name says) embed IPTC on your images. Watching the example from php.net I don't quite get it. Do I have to create my array manually in order to embed it on the new image. I guess there's an easy way to just copy one images IPTC's data and embed it into other image.

Any answer will be welcome. Thanks in advance.

like image 362
fedejp Avatar asked Nov 12 '22 23:11

fedejp


1 Answers

I think, this is quite simple. To get the iptc data from the old image, you just have to use the getimagesize and iptcparse functions.

On php.net you found this example to reach this

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

Combine this sample with the iptcembed method and you have everything you need

like image 184
Philipp Avatar answered Nov 15 '22 11:11

Philipp