Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4014,10 +4014,14 @@ PHP_FUNCTION(imagecropauto)
break;

case GD_CROP_THRESHOLD:
if (color < 0 || (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im))) {
if (color < 0) {
zend_argument_value_error(4, "must be greater than or equal to 0 when using the threshold mode");
RETURN_THROWS();
}
if (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im)) {
zend_argument_value_error(4, "must be a valid color index of the image when using the threshold mode");
RETURN_THROWS();
}
im_crop = gdImageCropThreshold(im, color, (float) threshold);
break;

Expand Down
2 changes: 1 addition & 1 deletion ext/gd/tests/bug72494.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ trycatch_dump(

?>
--EXPECT--
!! [ValueError] imagecropauto(): Argument #4 ($color) must be greater than or equal to 0 when using the threshold mode
!! [ValueError] imagecropauto(): Argument #4 ($color) must be a valid color index of the image when using the threshold mode
21 changes: 21 additions & 0 deletions ext/gd/tests/imagecropauto_threshold_palette_color.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
imagecropauto(): threshold mode, a color outside the palette
--EXTENSIONS--
gd
--FILE--
<?php
$p = imagecreate(6, 6);
imagecolorallocate($p, 255, 255, 255);
imagecolorallocate($p, 10, 10, 10);
foreach ([imagecolorstotal($p), -1, 1] as $color) {
try {
var_dump(imagecropauto($p, IMG_CROP_THRESHOLD, 0.5, $color) !== false);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
}
?>
--EXPECT--
ValueError: imagecropauto(): Argument #4 ($color) must be a valid color index of the image when using the threshold mode
ValueError: imagecropauto(): Argument #4 ($color) must be greater than or equal to 0 when using the threshold mode
bool(true)
Loading