Viewing 2 replies - 1 through 2 (of 2 total)
  • This is a very interesting question @nikiforova, I don’t have an authoritative answer for you, but I can share what I’ve found from reading into the issue you’ve reported.

    On my local test site (using ImageMagick Extension), I can confirm that I was able to upload a JPEG image and a PNG image containing rights metadata, and they were preserved in the original image when I downloaded it again from the site.

    When I resize a JPG image, the rights metadata is preserved. When I resize a PNG image, they appear to be stripped.

    1. Why does WP/Imagick handle PNG’s differently to JPG’s?

    From the sounds of it, this could be to do with how ImageMagick encodes PNG files, I found a similar issue reported on StackOverflow, where the user is dealing with Imagick directly, which seems to rule out WordPress from the mix. A quick look at the ImageMagick source seems to suggest that it should support saving exif data, but in practice that doesn’t seem to be happening here.

    2. Why didn’t any of the filter/s work?

    The image_strip_meta filter will allow filtering out metadata except for a list of protected profiles that include exif, iptc, and xmp, so that would be why you’d still be seeing metadata preserved even when setting the callback for the filter to __return_true.

    3. How can I make this happen?

    Unfortunately I don’t have any suggestions for getting this to work for PNG files, but so long as you’re using the Imagick extension, it sounds like you’ll be able to get consistent results for JPEG files.

    I hope that helps give a tiny bit more insight into what’s going on.

    Thread Starter nikiforova

    (@nikiforova)

    Thank you muchly for the pointers Andrew, most helpful and much appreciated!

    On point 1. I’ll start with a local test of ImageMagick resize and see what it does to jpg/png metadata. That should help me track down/isolate the issue (whether it’s WP or the imagick PHP extension).

    On point 2. Yes I’ve seen that WP source, and without further investigation, I took these comments literally (i.e. ONLY exif: Orientation data was preserved, etc…).

    But, it seems this protection does indeed apply to ALL metadata fields (as my results have indicated). So I removed lines 856-858 from /wp-includes/class-wp-image-editor-imagick.php and yes, the image_strip_meta filter with either __return_true (metadata is now stripped) or __return_false (metadata preserved) callbacks now works (for JPG’s at least, obviously I still need to figure out PNG’s per point 1.).

    My question now for the WP world at large is…

    What’s the point of the image_strip_meta filter, when all of the major image metadata types (exif/iptc/xmp) are protected anyways?

    Especially seeing as though there is no way to filter the protection in the WP source code (no that I could find). Meaning without the change I did to the core file, there is no way to actually use this filter?

    Thanks again!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘How to control WordPress image metadata (using Imagick)?’ is closed to new replies.