I'm trying to create a website where I can add and modify metadata within a JPEG file.
Is there a way in which I can write the exif data in a fairly easy way.
I have seen one or two examples, but they are they too complex to grasp in the timeframe I have been given.
I am aware of IPTC and I know metadata can be added to the JPEG file. But what would be the correct way of doing this?
If someone could provide some help on how to add metadata to JPEG using EXIF or IPTC or any other library or feature of PHP then I'd be highly appreciative.
Update:
First of all thanks for the reply by dbers.
I've looked through the code. I've managed to get it to add the default tags into the JPG.
I am still a bit confused as to what small portions of the code mean.
For example writing exif data in the php function:
function iptc_make_tag($rec, $data, $value)
{
$length = strlen($value);
$retval = chr(0x1C) . chr($rec) . chr($data);
...
}
I haven't come across a function variable, and how are $rec
, $data
and $value
being referenced if they havent been defined. Or are they taken from iptc_make_tag
?
I echoed out $rec
and $value
but I dont get a value back on screen.
if(isset($info['APP13']))
I'm not sure what APP13 means and when I try to echo out $info
, I just get the following when I echo out $info
in a table.
'2#120' => 'Test image', '2#116' => 'Copyright 2008-2009, The PHP Group'
I have no experience with this myself, but php's website has something that looks like what you're looking for:
http://php.net/manual/en/function.iptcembed.php
If thats what you meant when you said "I have seen one or two examples, but they are they too complex to grasp in the timeframe I have been given."
Then you may be in over your head.
But the examples on that page do not look hard to grasp at all.
Maybe u can try :
Imagick does let you set EXIF-data but only to objects in memory, when writing the file to disk these data is simply ignored. The most popular solution is to either shell out to exiftools or use the PHP-library PEL. The documentation of PEL is sparse, and the API is not really self-explanatory either.
I came across this problem when trying to add the correct EXIF-data to images that would be uploaded as 360 images to Facebook, which requires specific camera make and model to be specified as EXIF. The code below will open an image file, set its make and model, and save back to disk. If you are looking to set other EXIF-data there is a complete list of all supported PelTag-constants here in the PEL docs.
I know you found the solution, but this might help anyone else that s looking for the same thing!
I modified a class that I found here (thanks debers).
And all the references to IPTC tags can be readed from this PDF
And now the code (PHP >= 5.4):