Warnings to errors in imagecrop(auto)

This commit is contained in:
Mark 2019-09-04 01:53:16 +02:00 committed by Christoph M. Becker
parent b02f425b6c
commit 06a3dd536d
2 changed files with 22 additions and 17 deletions

View file

@ -3814,29 +3814,29 @@ PHP_FUNCTION(imagecrop)
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "x", sizeof("x") -1)) != NULL) {
rect.x = zval_get_long(tmp);
} else {
php_error_docref(NULL, E_WARNING, "Missing x position");
RETURN_FALSE;
zend_throw_error(NULL, "Cropping rectangle is missing x position");
return;
}
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "y", sizeof("y") - 1)) != NULL) {
rect.y = zval_get_long(tmp);
} else {
php_error_docref(NULL, E_WARNING, "Missing y position");
RETURN_FALSE;
zend_throw_error(NULL, "Cropping rectangle is missing y position");
return;
}
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "width", sizeof("width") - 1)) != NULL) {
rect.width = zval_get_long(tmp);
} else {
php_error_docref(NULL, E_WARNING, "Missing width");
RETURN_FALSE;
zend_throw_error(NULL, "Cropping rectangle is missing width");
return;
}
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(z_rect), "height", sizeof("height") - 1)) != NULL) {
rect.height = zval_get_long(tmp);
} else {
php_error_docref(NULL, E_WARNING, "Missing height");
RETURN_FALSE;
zend_throw_error(NULL, "Cropping rectangle is missing height");
return;
}
im_crop = gdImageCrop(im, &rect);
@ -3879,16 +3879,17 @@ PHP_FUNCTION(imagecropauto)
case GD_CROP_THRESHOLD:
if (color < 0 || (!gdImageTrueColor(im) && color >= gdImageColorsTotal(im))) {
php_error_docref(NULL, E_WARNING, "Color argument missing with threshold mode");
RETURN_FALSE;
zend_throw_error(NULL, "Color argument missing with threshold mode");
return;
}
im_crop = gdImageCropThreshold(im, color, (float) threshold);
break;
default:
php_error_docref(NULL, E_WARNING, "Unknown crop mode");
RETURN_FALSE;
zend_throw_error(NULL, "Unknown crop mode");
return;
}
if (im_crop == NULL) {
RETURN_FALSE;
} else {

View file

@ -6,10 +6,14 @@ if (!extension_loaded('gd')) die('skip gd extension not available');
?>
--FILE--
<?php
require __DIR__ . '/func.inc';
$im = imagecreate(10,10);
imagecropauto($im, IMG_CROP_THRESHOLD, 0, 1337);
trycatch_dump(
fn() => imagecropauto($im, IMG_CROP_THRESHOLD, 0, 1337)
);
?>
===DONE===
--EXPECTF--
Warning: imagecropauto(): Color argument missing with threshold mode in %s on line %d
===DONE===
--EXPECT--
!! [Error] Color argument missing with threshold mode