What is the simplest way to write XMP data to a JPEG image in PHP?

445 Views Asked by At

I only want to add the 2 fields required by Google for the Licensable badge:

  • Web Statement of Rights
  • Licensor URL

I'm able to write standard IPTC fields but these two seems to require XMP.

As a newbie, I've been searching for hours and got lost in a maze of classes, libraries, packages requiring Composer(?) or npm(?), cryptic examples assuming previous knowledge, downloaded stuff which doesn't work because I'm probably using them wrong, etc.

If someone could give me a code-complete example, or pointers to such, I'd much appreciate it.

3

There are 3 best solutions below

1
cOle2 On

Exiftool is my preferred way of writing XMP. There are some PHP libraries for using it but exec() can work as well if you know the commands.

A simple example for the Web Statement of Rights is:

exec('exiftool -xmp-xmpRights:WebStatement="http://example.com" image.jpg', $output, $returnCode);
1
Garr Lystad On

I had the same problem with the 127 error code on my Mac. Someone suggested that I put in the complete path to exiftool and that got rid of the 127 error. Now I have another error but at least it's coming from exiftool. On my Mac the pathname I used is /usr/local/bin/exiftool.

2
Thomas On

I have exactly the same problem like the original questioner and wonder if there's a solution in PHP, beside the exiftool which also doesn't work with me.

On a german magazine website I found the frustrating sentence: "XMP-Metadaten sind in PHP nicht vorgesehen." (engl. "XMP metadata is not intended in PHP.")

https://www.pc-magazin.de/ratgeber/php-iptc-exif-bearbeiten-3202457.html