2

I try to add keywords with this method

//echoing the img to check the path
echo "<img src='uploads/Background597x1050px.jpg'>";

//creating the object and use of setImageProperty method to add keywords
$imgi = new Imagick('uploads/Background597x1050px.jpg');
$imgi->setImageProperty('keywords','test');

When I download the image, nothing appears in the keyword part (screenshot in french) enter image description here

Edit: I also tried with the iptcembed method, but then the tag returned by iptcparse are only those and if I had tag added from windows property, they aren't return but with exif_read_data only and not the iptcembed ones

Richard
  • 994
  • 7
  • 26

3 Answers3

1

Imagick doesn't support other than comment property.

See

https://github.com/ImageMagick/ImageMagick/issues/55

https://github.com/Imagick/imagick/issues/124

Daniel W.
  • 31,164
  • 13
  • 93
  • 151
1

As Daniel W. already said, Imagick only supports the comment property for JPEG images.

This is mentioned in the php.net docs comments section: https://www.php.net/manual/en/imagick.setimageproperty.php#123346

To set other properties than comment for images, you would have to use other file types like PNG for your images.

electrophanteau
  • 1,322
  • 10
  • 12
1

So, you cannot use ImageMagick to do what you are trying to do and that is a bummer -- but that does not mean you are out of options. You have two that I can think of off the top of my head for dealing with EXIF and ITPC data in JPEG images:

  1. Use a 3rd party PHP library designed to work with EXIF data. The one I am specifically thinking of is called Pel and supports JPEG and TIFF images. From what I have read, it can be tricky to use and the documentation is sparse, but may be worth a try.

  2. Another option is called ExifTool, a handy command line utility that actually supports, EXIF, ITPC, XMP, among others (don't let the name fool you). If you add this command line tool to your server, you can then call it via PHP shell type commands and process the image that way. Just be aware that if the image is user input, you must be very careful to validate the image is actually an image, that the exif data doesn't have a payload injected, and do your absolute best to try to write as secure code as possible. One bit of code I found online calls ExifTool using exec(), but also calls escapeshellcommand() to clean the arguments when building the call. I suspect if you dig further up in that code, the images themselves are also being validated with things like getimagesize() and other techniques.

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133
  • First of all, Thank you for actually answering the question. You gave me enough directions to look at, I was a little bit lost there. I tried Pel, that didn't do the job. ExifTool is a solid yes, I was hoping to be taken by the hand to call accepted answer, but (after my own research) the main "stop" comes from how windows xp generation of OS encode meta data. So if someone got the same problem as me, take the point 2 of this answer and keep in mind you have to REWRITE old tags to keep your project clean. – Richard Feb 02 '21 at 10:08