Commit 1715e245dad for php

commit 1715e245dad721c587e0ff7708ed9b13d7f3a71e
Author: lacatoire <la.catoire@gmail.com>
Date:   Wed Nov 11 06:07:16 2026 +0000

    ext/gd: fix ValueError messages for imagecolormatch() and imagejpeg()

    The imagecolormatch() size-mismatch message cross-references argument #1 as
    $im1, a name the function lost in 14a26db3e2 when the ext/gd parameters were
    renamed for 8.0. Both parameters are $image1 and $image2.

    The imagejpeg() quality message read "must be at between -1 and 100". The
    sibling writers, imageavif() in particular, use the same bounds without the
    stray word.

    Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com>

    Close GH-23561

diff --git a/NEWS b/NEWS
index 5a865955281..ddcb2487e78 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,9 @@ PHP                                                                        NEWS
   . Use recommended TYPE, HELP order for OpenMetrics metadata.
     (Marcel Hernandez)

+- GD:
+  . Fixed imagecolormatch() and imagejpeg() ValueError messages. (lacatoire)
+
 - Hash:
   . Fixed mhash_keygen_s2k() truncating a $length above INT_MAX instead of
     throwing a ValueError. (Marc Bennewitz)
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index 0532b890c43..0adbe21cfbd 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -802,7 +802,7 @@ PHP_FUNCTION(imagecolormatch)
 			zend_argument_value_error(2, "must be Palette");
 			RETURN_THROWS();
 		case -3:
-			zend_argument_value_error(2, "must be the same size as argument #1 ($im1)");
+			zend_argument_value_error(2, "must be the same size as argument #1 ($image1)");
 			RETURN_THROWS();
 		case -4:
 			zend_argument_value_error(2, "must have at least one color");
@@ -2139,7 +2139,7 @@ PHP_FUNCTION(imagejpeg)
 	}

 	if (quality < -1 || quality > 100) {
-		zend_argument_value_error(3, "must be at between -1 and 100");
+		zend_argument_value_error(3, "must be between -1 and 100");
 		ctx->gd_free(ctx);
 		RETURN_THROWS();
 	}
diff --git a/ext/gd/tests/imagecolormatch_error4.phpt b/ext/gd/tests/imagecolormatch_error4.phpt
index 2c117dcd46a..4c3e11f4a6d 100644
--- a/ext/gd/tests/imagecolormatch_error4.phpt
+++ b/ext/gd/tests/imagecolormatch_error4.phpt
@@ -18,6 +18,13 @@
     echo $exception::class, ': ', $exception->getMessage(), "\n";
 }

+/* the message names argument #1, so that name has to be the real one */
+foreach ((new ReflectionFunction('imagecolormatch'))->getParameters() as $parameter) {
+    echo '$', $parameter->getName(), "\n";
+}
+
 ?>
 --EXPECT--
-ValueError: imagecolormatch(): Argument #2 ($image2) must be the same size as argument #1 ($im1)
+ValueError: imagecolormatch(): Argument #2 ($image2) must be the same size as argument #1 ($image1)
+$image1
+$image2
diff --git a/ext/gd/tests/imagejpeg_quality_range.phpt b/ext/gd/tests/imagejpeg_quality_range.phpt
new file mode 100644
index 00000000000..3a6aa292976
--- /dev/null
+++ b/ext/gd/tests/imagejpeg_quality_range.phpt
@@ -0,0 +1,31 @@
+--TEST--
+imagejpeg(): the accepted range of $quality and the message for values outside it
+--EXTENSIONS--
+gd
+--SKIPIF--
+<?php
+if (!function_exists('imagejpeg')) die('skip jpeg support unavailable');
+?>
+--FILE--
+<?php
+$image = imagecreatetruecolor(8, 8);
+$file = __DIR__ . '/imagejpeg_quality_range.jpeg';
+
+foreach ([-2, -1, 0, 100, 101] as $quality) {
+    try {
+        var_dump(imagejpeg($image, $file, $quality));
+    } catch (Throwable $e) {
+        echo $e::class, ': ', $e->getMessage(), "\n";
+    }
+}
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/imagejpeg_quality_range.jpeg');
+?>
+--EXPECT--
+ValueError: imagejpeg(): Argument #3 ($quality) must be between -1 and 100
+bool(true)
+bool(true)
+bool(true)
+ValueError: imagejpeg(): Argument #3 ($quality) must be between -1 and 100
diff --git a/ext/gd/tests/imageresolution_jpeg.phpt b/ext/gd/tests/imageresolution_jpeg.phpt
index a918c7402d2..fcca0f7f279 100644
--- a/ext/gd/tests/imageresolution_jpeg.phpt
+++ b/ext/gd/tests/imageresolution_jpeg.phpt
@@ -43,7 +43,7 @@
   [1]=>
   int(299)
 }
-ValueError: imagejpeg(): Argument #3 ($quality) must be at between -1 and 100
+ValueError: imagejpeg(): Argument #3 ($quality) must be between -1 and 100
 --CLEAN--
 <?php
 @unlink(__DIR__ . DIRECTORY_SEPARATOR . 'imageresolution_jpeg.jpeg');