Repository navigation
Conversation
As of PHP 8.6, `exif_read_data()` can read Exif data from WebP images. `wp_read_image_metadata()` only passes JPEG and TIFF images to it by default, so a WebP image carrying Exif data gets no credit, copyright, camera or orientation metadata. `IMAGETYPE_WEBP` is now included in the default list passed to the `wp_read_image_metadata_types` filter when running on PHP 8.6 or later. Earlier versions are unchanged.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
desrosj
left a comment
There was a problem hiding this comment.
This is a good starting point, @AceMedia! A few things that I noticed while reviewing and testing.
First, I noticed that a E_WARNING "Invalid WebP file" is emitted when a WebP file does not have any EXIF data (which will likely be a large percentage). This is a bit different than how JPEGs are handled, returning an empty array with no warning. The printed warning text breaks sites when WP_DEBUG is on.
The tests are not catching it because WP_RUN_CORE_TESTS is defined in Core's test suite, which uses @ on the call to suppress notices and warnings. It looks like HEIF files also have this inconsistent behavior, so it should likely be flagged upstream in https://github.com/php/php-src/.
Next, it looks like test_exif_webp_is_not_read_before_php_8_6 will never fail. A better test would be to check the contents of default array to confirm that IMAGETYPE_WEBP is not present.
Lastly, I think it could be good to add the automatic rotation based on EXIF data (and anything else that is changed by reading that data) at the same time. But let's not add it just yet.
|
Looks like you've already flagged this upstream for WebP in php/php-src#25678 / php/php-src#25679. Thanks! |
On PHP 8.6.0, `exif_read_data()` raises an "Invalid WebP file" warning and returns `false` for a WebP image that has no Exif chunk. `wp_read_image_metadata()` now checks the Exif flag in the `VP8X` header through a new private function, `_wp_webp_has_exif_data()`, and skips `exif_read_data()` for a WebP image without it. The test that could not fail is replaced by one that checks the default image types passed to the `wp_read_image_metadata_types` filter, and a new test confirms that WebP images without Exif data raise no error. Follow-up to review feedback from desrosj. See #66789.
|
Thanks for testing this, both points were right. I reproduced the warning on PHP 8.6.0: I've replaced I haven't looked at HEIF here, and I've left rotation out as you suggested. The change and the test runs (PHP 8.4.25, 8.5.12 and 8.6.0) were done with Claude Code. |
As of PHP 8.6,
exif_read_data()can read Exif data from WebP images.wp_read_image_metadata()only passes JPEG and TIFF images to it by default, so a WebP image carrying Exif data gets no credit, copyright, camera or orientation metadata, although the runtime can read it.This includes
IMAGETYPE_WEBPin the default list passed to thewp_read_image_metadata_typesfilter when running on PHP 8.6 or later. Earlier versions are unchanged, and the filter can still remove the type.On PHP 8.6.0,
exif_read_data()raises an "Invalid WebP file" warning and returnsfalsefor a WebP image with no Exif chunk (reported upstream in php/php-src#25678). To avoid that, a WebP image is only passed toexif_read_data()when itsVP8Xheader has the Exif flag set, checked by a new private function,_wp_webp_has_exif_data()(added after review feedback from @desrosj).It adds a 162-byte synthetic WebP fixture with Exif data and tests for: reading Exif data from WebP on PHP 8.6 and later, the default image types passed to the filter on either side of 8.6, WebP images without Exif data raising no error, and the new function.
Testing
tests/image/meta.php, with the exif extension loaded:It also passes on PHP 8.4.25 (25 tests, 119 assertions, 1 skip). On PHP 8.6.0,
--group image,mediapasses with this change (1,090 tests, 12,895 assertions, 54 skips). Before the review changes, the first version of the WebP test failed on PHP 8.6.0 with trunk's source because the credit was empty.PHPCS passes on the changed files.
Notes for review
@since 7.3.0because trunk is at 7.2-RC2. Please correct it if this should land elsewhere.test-image-rotated-90cw.webpalready has an orientation tag (8), so on PHP 8.6 itsimage_metaorientation would be stored as 8 rather than 0. Rotation is not changed here:WP_Image_Editor::maybe_exif_rotate()still only reads the tag forimage/jpeg. That could be a follow-up.Trac ticket: https://core.trac.wordpress.org/ticket/66789
Use of AI Tools
AI assistance: Yes
Tool(s): Codex, Claude Code
Used for: Assessing the PHP 8.6 change against Core, writing the change, the fixture, the tests and this description, and running the tests. The test results above are automated runs by those tools.