Skip to content

Commit 06a3dd5

Browse files
marandallcmb69
authored andcommitted
Warnings to errors in imagecrop(auto)
1 parent b02f425 commit 06a3dd5

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

ext/gd/gd.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,29 +3814,29 @@ PHP_FUNCTION(imagecrop)
38143814
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) {
38153815
rect.x = zval_get_long(tmp);
38163816
} else {
3817-
php_error_docref(NULL, E_WARNING, "Missing x position");
3818-
RETURN_FALSE;
3817+
zend_throw_error(NULL, "Cropping rectangle is missing x position");
3818+
return;
38193819
}
38203820

38213821
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
38223822
rect.y = zval_get_long(tmp);
38233823
} else {
3824-
php_error_docref(NULL, E_WARNING, "Missing y position");
3825-
RETURN_FALSE;
3824+
zend_throw_error(NULL, "Cropping rectangle is missing y position");
3825+
return;
38263826
}
38273827

38283828
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
38293829
rect.width = zval_get_long(tmp);
38303830
} else {
3831-
php_error_docref(NULL, E_WARNING, "Missing width");
3832-
RETURN_FALSE;
3831+
zend_throw_error(NULL, "Cropping rectangle is missing width");
3832+
return;
38333833
}
38343834

38353835
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
38363836
rect.height = zval_get_long(tmp);
38373837
} else {
3838-
php_error_docref(NULL, E_WARNING, "Missing height");
3839-
RETURN_FALSE;
3838+
zend_throw_error(NULL, "Cropping rectangle is missing height");
3839+
return;
38403840
}
38413841

38423842
im_crop = gdImageCrop(im, &rect);
@@ -3879,16 +3879,17 @@ PHP_FUNCTION(imagecropauto)
38793879

38803880
case GD_CROP_THRESHOLD:
38813881
if (color < 0 || (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im))) {
3882-
php_error_docref(NULL, E_WARNING, "Color argument missing with threshold mode");
3883-
RETURN_FALSE;
3882+
zend_throw_error(NULL, "Color argument missing with threshold mode");
3883+
return;
38843884
}
38853885
im_crop = gdImageCropThreshold(im, color, (float) threshold);
38863886
break;
38873887

38883888
default:
3889-
php_error_docref(NULL, E_WARNING, "Unknown crop mode");
3890-
RETURN_FALSE;
3889+
zend_throw_error(NULL, "Unknown crop mode");
3890+
return;
38913891
}
3892+
38923893
if (im_crop == NULL) {
38933894
RETURN_FALSE;
38943895
} else {

ext/gd/tests/bug72494.phpt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ if (!extension_loaded('gd')) die('skip gd extension not available');
66
?>
77
--FILE--
88
<?php
9+
require __DIR__ . '/func.inc';
10+
911
$im = imagecreate(10,10);
10-
imagecropauto($im, IMG_CROP_THRESHOLD, 0, 1337);
12+
13+
trycatch_dump(
14+
fn() => imagecropauto($im, IMG_CROP_THRESHOLD, 0, 1337)
15+
);
16+
1117
?>
12-
===DONE===
13-
--EXPECTF--
14-
Warning: imagecropauto(): Color argument missing with threshold mode in %s on line %d
15-
===DONE===
18+
--EXPECT--
19+
!! [Error] Color argument missing with threshold mode

0 commit comments

Comments
 (0)