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

View file

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