Make WordPress Core

Changeset 61328


Ignore:
Timestamp:
12/01/2025 12:34:20 AM (4 weeks ago)
Author:
desrosj
Message:

Media: Adjustments for official HEIF/HEIC support in added in PHP 8.5.

Now that a version of imagick with support for PHP 8.5 has been released and the containers maintained by the project for the local development environemnt have been updated to include it, there are some new PHP 8.5 compatibility issues that have surfaced related to HEIF/HEIC image format.

PHP 8.5 added support for the HEIF/HEIC image format in getimagesize(). To properly support this in a cross-version way, a few changes are necessary.

Since [58849], WordPress has supported this format and the IMAGETYPE_HEIC constant was introduced as a placeholder until proper support was added in PHP. Since that has now happened, this constant needs to be changed to contain a value of 20 instead of 99, and the name upstream was added as IMAGETYPE_HEIF. The constant in Core is being changed to match those included in PHP.

The implementation for this image format in getimagesize() also follows a similar pattern to that of AVIF where additional information such as the image bits and channels are also returned. This additional information is causing unit tests to fail. The tests have been updated to account for different versions of PHP returning a different level of detail.

Props westonruter, skithund, johnbillion, adamsilverstein.
Fixes #64322.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/compat.php

    r60969 r61328  
    615615}
    616616
    617 // IMAGETYPE_HEIC constant is not yet defined in PHP as of PHP 8.3.
    618 if ( ! defined( 'IMAGETYPE_HEIC' ) ) {
    619     define( 'IMAGETYPE_HEIC', 99 );
    620 }
     617// IMAGETYPE_HEIF constant is only defined in PHP 8.5 or later.
     618if ( ! defined( 'IMAGETYPE_HEIF' ) ) {
     619    define( 'IMAGETYPE_HEIF', 20 );
     620}
  • trunk/src/wp-includes/media.php

    r60910 r61328  
    58305830                $size['width'],
    58315831                $size['height'],
    5832                 IMAGETYPE_HEIC,
     5832                IMAGETYPE_HEIF,
    58335833                sprintf(
    58345834                    'width="%d" height="%d"',
  • trunk/tests/phpunit/tests/functions.php

    r60810 r61328  
    15741574            1180,
    15751575            1180,
    1576             IMAGETYPE_HEIC,
     1576            IMAGETYPE_HEIF,
    15771577            'width="1180" height="1180"',
    1578             'mime' => 'image/heic',
    1579         );
    1580         $result   = wp_getimagesize( $file );
     1578        );
     1579
     1580        // As of PHP 8.5.0, getimagesize() supports HEIF/HEIC files.
     1581        if ( PHP_VERSION_ID >= 80500 ) {
     1582            $expected = array_merge(
     1583                $expected,
     1584                array(
     1585                    'bits'        => 8,
     1586                    'channels'    => 3,
     1587                    'mime'        => 'image/heif',
     1588                    'width_unit'  => 'px',
     1589                    'height_unit' => 'px',
     1590                )
     1591            );
     1592        } else {
     1593            $expected['mime'] = 'image/heic';
     1594        }
     1595
     1596        $result = wp_getimagesize( $file );
    15811597        $this->assertSame( $expected, $result );
    15821598    }
Note: See TracChangeset for help on using the changeset viewer.