• In short, I’m having trouble with the WordPress Media Library image editor and how it handles metadata.

    I use the Imagick PHP extension (but also tested with GD for comparison), and in all environments (localhost/dev/staging/prod), and with no other plugins installed/enabled, the below table shows what happened to image metadata (JPG & PNG/resized & original) post image upload. Photo’s with native camera metadata and images processed with metadata set by Gimp and ExifTool were tested. Given the consistent results, I don’t believe any metadata gremlins were a factor.

    GD performed as I’d expected (*I understand the filters do not work for GD*). And in all cases, original images were unchanged (as expected).

    Imagick however: 1. stripped all resized .png metadata by default. & 2. Did not change it’s behavior with any of the below filters (set to either true or false – NONE of them worked).

    So:
    1. Why does WP/Imagick handle PNG’s differently to JPG’s?
    2. Why didn’t any of the filter/s work? &
    3. How can I make this happen? –
    I specifically set XMP rights metadata (per [this][1]) on all images (.jpg/.png). When I upload them to WordPress, I would like that metadata to persist across all resized images.

    If anybody else can share their own test results/findings and/or reproduce my results I’d be happy to hear it! ??

    Thanks in advance!

      Results

    GD only – Resized JPG’s EXIF/IPTC/XMP stripped, Original JPG All Metadata Kept
    GD only – Resized PNG’s EXIF/IPTC/XMP stripped, Original PNG All Metadata Kept
    GD + Any Filter – Resized JPG’s EXIF/IPTC/XMP stripped, Original JPG All Metadata Kept
    GD + Any Filter – Resized PNG’s EXIF/IPTC/XMP stripped, Original PNG All Metadata Kept

    Imagick only – Resized JPG’s EXIF/IPTC/XMP Kept, Original JPG All Metadata Kept
    Imagick only – Resized PNG’s EXIF/IPTC/XMP stripped, Original PNG All Metadata Kept
    Imagick + Any Filter – Resized JPG’s EXIF/IPTC/XMP Kept, Original JPG All Metadata Kept
    Imagick + Any Filter – Resized PNG’s EXIF/IPTC/XMP stripped, Original PNG All Metadata Kept

      Attempted Filters

    
        // Showing a mix of true/false values below, but true && false tried for each filter. Each filter attempted separately.
        
        // Filter 1 - I believe this syntax is incorrect
        add_filter ( 'image_strip_meta', true );
        
        // Filter 2
        add_filter ( 'image_strip_meta', '__return_false' );
        
        // Filter 2 - with priority set
        add_filter ( 'image_strip_meta', '__return_true', 100 );
        
        // Filter 3
        add_filter( 'image_strip_meta', function( $arg ) {
        	return false;
        } );
    

      Tested Hosts

    Localhost XAMPP (LAMPP) – Vanilla WordPress build
    WordPress 5.8
    Twenty Twenty One Theme
    No other Plugins/Theme’s installed/enabled.
    PHP 7.4.22

    &

    Live Web Server
    WordPress 5.8
    Storefront Theme & Twenty Twenty One Theme Tetsed
    All other Plugins disabled.
    PHP 7.4.22

    GD Extension
    | GD Version | bundled (2.1.0 compatible) |
    | FreeType Version | 2.4.8 |
    | JPEG Support | enabled |
    | libJPEG Version | 9 compatible |
    | PNG Support | enabled |
    | libPNG Version | 1.6.37 |
    | WBMP Support | enabled |

    Imagick Extension
    | imagick module version | 3.5.1 |
    | imagick classes | Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel |
    | Imagick compiled with ImageMagick version | ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org |
    | Imagick using ImageMagick library version | ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org |
    | ImageMagick release date | 2021-01-25 |
    | ImageMagick number of supported formats: | 242 |
    | ImageMagick supported formats | 3FR, 3G2, 3GP, AAI, AI, APNG, ART, ARW, AVI, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, FAX, FILE, FITS, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, H, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIDEO, VIFF, VIPS, VST, WBMP, WEBM, WEBP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV |

    [1]: https://iptc.org/standards/photo-metadata/quick-guide-to-iptc-photo-metadata-and-google-images/

    The page I need help with: [log in to see the link]

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.