Problem/Motivation

The ToolkitGdTest test fails on PHP 8.5 probably because of

- https://github.com/php/php-src/pull/13443
- https://github.com/php/php-src/pull/18940

maybe related
- https://github.com/php/php-src/pull/17375
- https://github.com/php/php-src/pull/19107

Steps to reproduce

See the latest pipeline in https://git.drupalcode.org/project/drupal/-/merge_requests/12877/pipelines

https://git.drupalcode.org/issue/drupal-3523596/-/jobs/6224316

     ✘ Manipulations with 29
       ┐
       ├ Image 'image-test.gif' object after 'rotate_5' action has the correct color placement at corner '0' - Actual: {255,0,93,0}, Expected: {255,0,255,0}, Distance: 26244, Tolerance: 0
       ├ Failed asserting that 26244 is equal to 0 or is less than 0.             
       │
       │ /builds/issue/drupal-3523596/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php:90
       │ /builds/issue/drupal-3523596/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php:357
       ┴
     ✘ Manipulations with 30
       ┐
       ├ Image 'image-test.gif' object after 'rotate_transparent_5' action has the correct color placement at corner '0' - Actual: {255,93,0,46}, Expected: {255,255,255,127}, Distance: 97830, Tolerance: 0
       ├ Failed asserting that 97830 is equal to 0 or is less than 0.             
       │
       │ /builds/issue/drupal-3523596/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php:90
       │ /builds/issue/drupal-3523596/core/tests/Drupal/KernelTests/Core/Image/ToolkitGdTest.php:357
       ┴

Proposed resolution

find out why rotation failing and fix
get feedback from https://github.com/php/php-src/issues/20201

Remaining tasks

MR, review, commit

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3540531

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

andypost created an issue. See original summary.

andypost’s picture

Title: Fix ToolkitGdTest n PHP 8.5 » Fix ToolkitGdTest for PHP 8.5
andypost’s picture

Issue summary: View changes

taran2l made their first commit to this issue’s fork.

andypost’s picture

Created testing branch with patches to run tests on 8.5 from #3523596: [meta] PHP 8.5 support

taran2l’s picture

So, my idea was to recreate the file itself (maybe it has encoding issues), but that didn't work ...

andypost’s picture

Status: Active » Needs work

Thank you, looks like good idea but I think the rotation got changes(

andypost’s picture

taran2l’s picture

Seems like rotation is affected either by our code or by how PHP8.5 handles it, as all rotate to 5 degrees tests are broken (file format is not relevant, it happens for all of them)

See https://git.drupalcode.org/issue/drupal-3540531/-/jobs/6225263#L2188

The other part is AVIF, I assume Docker image does not have AVIF support at all (or it's broken in PHP itself)

taran2l’s picture

So, it seems that the default interpolation algorithm has been changed, see https://github.com/php/php-src/pull/17375/files#diff-a6d1ba8e66261eacec5...

That probably means that we need to adjust test to that

taran2l changed the visibility of the branch 3540531-fix-toolkitgdtest-for to hidden.

andypost’s picture

IIRC we fixed AVIF long time ago by using Ubuntu as a source for CI images

mondrake’s picture

Priority: Normal » Critical

This is critical to support PHP 8.5.

taran2l changed the visibility of the branch 3540531-fix-toolkitgdtest-for to active.

taran2l’s picture

So, the GD issue with rotate was indeed related to the default interpolation method change (should core now keep the BC and set it explicitly?)

The AVIF issues is mystery, as it fails on loading the image rather than processing. Is AVIF part of the docker image?

And due to new deprecations (PDO constants) most of the tests are red

taran2l changed the visibility of the branch 3540531-test-on-php-85 to hidden.

andypost’s picture

I think BC layer should be added at least with condition PHP_VERSION_ID < 80500

AVIF should be working, it's added to CI images since PHP 8.1 so all images reports it\s supported, maybe needs better check but

$ docker run --rm drupalci/php-8.5-ubuntu-apache:production php --ri gd

gd

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.13.2
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 8
PNG Support => enabled
libPNG Version => 1.6.43
WBMP Support => enabled
XBM Support => enabled
WebP Support => enabled
BMP Support => enabled
AVIF Support => enabled
TGA Read Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => On => On
andypost’s picture

btw runnign php's tests it reports no issues with AVIF, so probably something wrong in core's code or maybe we need to report something to php upstream

PS few more fixes for beta2 added in #3523596: [meta] PHP 8.5 support and the only failures left because of composer's dependecy which should be fixed later this week https://github.com/jsonrainbow/json-schema/pull/840

taran2l’s picture

I think PHP has broken AVIF detection by introducing HEIF/HEIC support here https://github.com/php/php-src/commit/dfac2da7fba930570fcda99205cfcf53db...

taran2l’s picture

The problem is that HEIF image can ... pretend not not be HEIF, and ... be an AVIF

See https://github.com/nokiatech/heif/issues/74 for details

Our test image is like example C034.heic:

0x0000001C  // 28-bytes: size of 'ftyp' box.
'ftyp'      // boxtype
'mif1'      // major_brand
0x00000000  // minor_version
'mif1'      // compatible_brands[0]
'avid'      // compatible_brands[1]
'miaf'      // compatible_brands[2]

so it has mif1 and avif, but no hei* ... but PHP detects mif1 first and decides that the file is a HEIF image, which it's not true in this case

andypost’s picture

Thank you finding it, missed this change... btw curious how they added support without libheif, cos they are not 100% compatible and very probably ubuntu:noble has somehow outdated libavif.

I will check what GD library (which is bundled into PHP) supports to link to as Ubuntu contains libavif16 - 1.0.4 but upstream is 1.3.0 and starting with 1.2.0 it has experimental support for HEIF under experimental flag

Add experimental support for PixelInformationProperty syntax from HEIF 3rd Ed.
Amd2 behind the compilation flag AVIF_ENABLE_EXPERIMENTAL_EXTENDED_PIXI.

taran2l’s picture

so, it does not support HEIF for processing, only for getting the image dimensions - and the code to do that is the same as avif:

		case IMAGE_FILETYPE_AVIF:
			result = php_handle_avif(stream);
			break;
		case IMAGE_FILETYPE_HEIF:
			if (!php_stream_rewind(stream)) {
				result = php_handle_avif(stream);
			}
			break;

and the reason for that is (I believe): both standards are basically use the same container format ... technically AVIF is an AV1 encoded image in HEIF container, while HEIC is an HEVC encoded image in HEIF container. Very confusing actually :D

andypost’s picture

set of commits merged for heic so next release can help to move forward

ref https://github.com/php/php-src/commit/02c13b67bcf1eb122543ca4ba337499412...

andypost’s picture

Issue summary: View changes
Issue tags: +Vienna2025
mondrake’s picture

Assigned: Unassigned » mondrake

AVIF images misdetected as HEIF after introducing HEIF support in getimagesize() was fixed upstream so in PHP 8.5RC4 we should not longer have that part to be solved.

What remains is the different default interpolation used in PHP 8.5 vs earlier versions.

This test is one of the longest running kernel tests, I think it would make sense to split it in an abstract base class and one concrete test class per image type (gif, png, webp, etc.).
It should not be that hard, will try to look into it.

mondrake’s picture

Status: Needs work » Needs review

IMHO

imagesetinterpolation($toolkit->getImage(), IMG_NEAREST_NEIGHBOUR);

should be placed in the toolkit code, conditionally on the PHP version, not in the test. Otherwise we'd be testing something that does not match the normal runtime behavior.

Or, we need to have different reference values to check against (again, PHP version-dependent).

Setting to NR for comments.

andypost’s picture

updated 8.5 image is pushed (contains fix for AVIF/HEIF)

mondrake’s picture

Assigned: mondrake » Unassigned

#29 - thanks @andypost, AVIF now looks OK in latest tests.

#28 - In the end I think we should be testing conditionally on PHP version, without changing the default interpolation algo. Latest commit does that.

mondrake’s picture

All the new Kernel tests (one per image type) are green on PHP 8.5 now.

andypost’s picture

Assigned: Unassigned » acbramley
Status: Needs review » Reviewed & tested by the community

Thank you! I think it ready to go and improving tests

PS: added MR's diff for testing and now only composer's tests fail https://git.drupalcode.org/issue/drupal-3523596/-/pipelines/645292

andypost’s picture

Assigned: acbramley » Unassigned

sorry

mondrake’s picture

Out of curiosity, I checked out the rotated image derivatives from the CI runs, and they're actually quite different in PHP 8.4 and 8.5 (obviously, on the pixel level: you need to zoom in the image quite a lot to see a human perceivable difference). Attaching here.

This is an area where local testing may yield different results, as PHP with the embedded GD library (that Drupal GitLabCI uses) has code quite different from PHP that links the library separately, as #2921123: Adjust Rectangle class to calculate rotated image dimensions according to libgd 2.2.2+ shown extensively.

andypost’s picture

Drupal GitLabCI

is using bundled into php-src forked source of libgd which is updated but other envs can try link to system library which usually very dated

taran2l’s picture

Nice to see it finally almost in.

alexpott’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 419838e7841 to 11.x and 99e7d471466 to 11.3.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • alexpott committed 99e7d471 on 11.3.x
    Issue #3540531 by andypost, taran2l, mondrake: Fix ToolkitGdTest for PHP...

  • alexpott committed 419838e7 on 11.x
    Issue #3540531 by andypost, taran2l, mondrake: Fix ToolkitGdTest for PHP...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.