From f26dd1354b9ceafd4aeaa3318112000e463f7f85 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 25 Jan 2024 23:30:23 +0100 Subject: [PATCH] Fix GH-10614: imagerotate will turn the picture all black, when rotated 90 This is a backport of the upstream libgd PR that was recently committed [1]. [1] https://github.com/libgd/libgd/pull/862 Closes GH-13246. --- NEWS | 2 + ext/gd/libgd/gd_rotate.c | 6 +-- ext/gd/tests/gh10614.phpt | 93 ++++++++++++++++++++++++++++++++++++++ ext/gd/tests/gh10614.png | Bin 0 -> 98 bytes 4 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 ext/gd/tests/gh10614.phpt create mode 100644 ext/gd/tests/gh10614.png diff --git a/NEWS b/NEWS index 174233753b0..8bc955af3d2 100644 --- a/NEWS +++ b/NEWS @@ -19,6 +19,8 @@ PHP NEWS - GD: . Fixed bug GH-10344 (imagettfbbox(): Could not find/open font UNC path). (nielsdos) + . Fixed bug GH-10614 (imagerotate will turn the picture all black, when + rotated 90). (nielsdos) - MySQLnd: . Fixed bug GH-12107 (When running a stored procedure (that returns a result diff --git a/ext/gd/libgd/gd_rotate.c b/ext/gd/libgd/gd_rotate.c index cc89652f03f..53c6c9470db 100644 --- a/ext/gd/libgd/gd_rotate.c +++ b/ext/gd/libgd/gd_rotate.c @@ -216,7 +216,7 @@ gdImagePtr gdImageRotate90 (gdImagePtr src, int ignoretransparent) if (dst != NULL) { int old_blendmode = dst->alphaBlendingFlag; dst->alphaBlendingFlag = 0; - + dst->saveAlphaFlag = 1; dst->transparent = src->transparent; gdImagePaletteCopy (dst, src); @@ -263,7 +263,7 @@ gdImagePtr gdImageRotate180 (gdImagePtr src, int ignoretransparent) if (dst != NULL) { int old_blendmode = dst->alphaBlendingFlag; dst->alphaBlendingFlag = 0; - + dst->saveAlphaFlag = 1; dst->transparent = src->transparent; gdImagePaletteCopy (dst, src); @@ -311,7 +311,7 @@ gdImagePtr gdImageRotate270 (gdImagePtr src, int ignoretransparent) if (dst != NULL) { int old_blendmode = dst->alphaBlendingFlag; dst->alphaBlendingFlag = 0; - + dst->saveAlphaFlag = 1; dst->transparent = src->transparent; gdImagePaletteCopy (dst, src); diff --git a/ext/gd/tests/gh10614.phpt b/ext/gd/tests/gh10614.phpt new file mode 100644 index 00000000000..c0689141837 --- /dev/null +++ b/ext/gd/tests/gh10614.phpt @@ -0,0 +1,93 @@ +--TEST-- +GH-10614 (imagerotate will turn the picture all black, when rotated 90) +--EXTENSIONS-- +gd +--SKIPIF-- +=')) die("skip test requires GD 2.3.4 or older"); +?> +--FILE-- + +--EXPECT-- +--- Angle 0 --- +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +--- Angle 90 --- +string(8) "7f000000" +string(8) "7f000000" +string(1) "0" +string(1) "0" +string(8) "7f000000" +string(8) "7f000000" +string(1) "0" +string(1) "0" +string(8) "7f000000" +string(8) "7f000000" +string(1) "0" +string(1) "0" +string(8) "7f000000" +string(8) "7f000000" +string(1) "0" +string(1) "0" +--- Angle 180 --- +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(8) "7f000000" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +string(1) "0" +--- Angle 270 --- +string(1) "0" +string(1) "0" +string(8) "7f000000" +string(8) "7f000000" +string(1) "0" +string(1) "0" +string(8) "7f000000" +string(8) "7f000000" +string(1) "0" +string(1) "0" +string(8) "7f000000" +string(8) "7f000000" +string(1) "0" +string(1) "0" +string(8) "7f000000" +string(8) "7f000000" diff --git a/ext/gd/tests/gh10614.png b/ext/gd/tests/gh10614.png new file mode 100644 index 0000000000000000000000000000000000000000..baf1ea92fc9ce3dcf9c432876ec32f4de97d8dc4 GIT binary patch literal 98 zcmeAS@N?(olHy`uVBq!ia0vp^EFjFm1|(O0oL2|p6gzo_Z~#FKM@k2fFX`#x7{W0# oIUyn82metX5b)v2XxPBOP&0*z_4C4BZ=fOuPgg&ebxsLQ0Hm}QTmS$7 literal 0 HcmV?d00001