[php-src] master: ext/gd: fix ValueError messages for imagecolormatch() and imagejpeg()

From: Date: Wed, 11 Nov 2026 06:08:57 +0000
Subject: [php-src] master: ext/gd: fix ValueError messages for imagecolormatch() and imagejpeg()
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143562@lists.php.net to get a copy of this message
Author: lacatoire (lacatoire) Committer: David Carlier (devnexen) Date: 2026-11-11T06:07:16Z Commit: https://github.com/php/php-src/commit/1715e245dad721c587e0ff7708ed9b13d7f3a71e Raw diff: https://github.com/php/php-src/commit/1715e245dad721c587e0ff7708ed9b13d7f3a71e.diff 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 Changed paths: A ext/gd/tests/imagejpeg_quality_range.phpt M NEWS M ext/gd/gd.c M ext/gd/tests/imagecolormatch_error4.phpt M ext/gd/tests/imageresolution_jpeg.phpt Diff: diff --git a/NEWS b/NEWS index 5a865955281d..ddcb2487e78d 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 0532b890c43e..0adbe21cfbdb 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 2c117dcd46ab..4c3e11f4a6de 100644 --- a/ext/gd/tests/imagecolormatch_error4.phpt +++ b/ext/gd/tests/imagecolormatch_error4.phpt @@ -18,6 +18,13 @@ try { 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 000000000000..3a6aa292976e --- /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 a918c7402d2c..fcca0f7f279f 100644 --- a/ext/gd/tests/imageresolution_jpeg.phpt +++ b/ext/gd/tests/imageresolution_jpeg.phpt @@ -43,7 +43,7 @@ array(2) { [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');

« previous php.cvs (#143562) next »