How to control WordPress image metadata (using Imagick)?
-
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 KeptImagick 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.22GD 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]
- The topic ‘How to control WordPress image metadata (using Imagick)?’ is closed to new replies.