Skip to content

Instantly share code, notes, and snippets.

@boulama
Created November 5, 2021 06:43
Show Gist options
  • Save boulama/a2ff8ae7afef37f4872e09e2a272f8c6 to your computer and use it in GitHub Desktop.
Save boulama/a2ff8ae7afef37f4872e09e2a272f8c6 to your computer and use it in GitHub Desktop.
Simple php function that writes IPTC data in a JPG image.
<?php
/*
Simple php function that writes IPTC data in a JPG image.
Details here: https://www.iptc.org/std/photometadata/specification/IPTC-PhotoMetadata
https://www.php.net/manual/en/function.iptcembed.php
*/
function write_iptc($rec, $data, $value)
{
$length = strlen($value);
$retval = chr(0x1C) . chr($rec) . chr($data);
if($length < 0x8000)
{
$retval .= chr($length >> 8) . chr($length & 0xFF);
}
else
{
$retval .= chr(0x80) .
chr(0x04) .
chr(($length >> 24) & 0xFF) .
chr(($length >> 16) & 0xFF) .
chr(($length >> 8) & 0xFF) .
chr($length & 0xFF);
}
return $retval . $value;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment